Measure to count across multiple columns - powerbi

I am new to Power BI - DAX functions.
I have three columns in a table with text in it and I have added a fourth column where I want the count of these three but when I use COUNTA, COUNTX or COUNTAX measure I am getting the count of the entire column.
COUNTA
COUNTAX
COUNTX
Column = COUNTX(Table1, Table1[First_Amendment])
+ COUNTX(Table1, Table1[Second_Amendment])
+ COUNTX(Table1, Table1[Third_Amendment])
Suppose column A, B, C contains three names, apple, mango, oranges respectively so in fourth column I should get count as 3.

Did you want to count no blank column based on row, right?
If so, you could try to use calculated column like below
Column = if((countaa[a])="",0,1)+if((countaa[b])="",0,1)+if((countaa[c])="",0,1)
You also could refer to this post for details.
Zoe

Related

Dax measure (add new columns) not showing total in table

I use DAX to add two new columns "netWeight_Shipped" and "NetWeight_notShipped" based on existing column "NetWeight_Total" and groupped by "BatchNo" and filtered by OutStockTransactionID as below:
--New column
NetWeight_Shipped =
CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] <> 0
)
--New column
NetWeight_notShipped =
CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] = 0
)
Then put those columns on table as the screenshot. However, two new columns not showing total values in table.
What should I change to have total values for those new columns?
In order to display total values in the table, you should create and use two new measures "netWeight_Shipped" and "NetWeight_notShipped" based on the existing columns, but not two new columns.
-- New measure
NetWeight_Shipped = CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] <> 0
)
-- New measure
NetWeight_notShipped = CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] = 0
)
You should apply aggregation to your column to see the total value below. Look at this image I have added the same column twice and for the first one, there is no total value. But for the second one, there is a total. This is only for the aggregation I applied to the second column but not to the first column-

Get sum of column values for specific rows only | Get sum of sales for each country

I am super new to power bi and Dax and i need to create a calculated column in which i have the total sales for each country respectively.
Here is a screenshot with an oversimplified scenario but if i can do it for this data i can do it in my actual project since the concept is the same.
The column TotalSalesPerCountry is the calculated column.
And here is what the column should look like if it worked. (Colors are just for visual representation)
Basically everywhere you see the same country you should see the same TotalSalesPerCountry values which are calculated by sum-ing the Sales for those countries over the years.
Another DAX function:
= CALCULATE(SUM(CountrySales[Sales]), FILTER(CountrySales, CountrySales[Country] = EARLIER (CountrySales[Country])))
This is simple to do in DAX. Add the column:
TotalSalesPerCountry =
var curCountry = yourTable[Country]
return CALCULATE(SUM(Sales), FILTER(yourTable, curCountry = yourTable[Country]))
Explanation:
For each row in the table, get the country. Filter yourTable on the curCountry and SUM this together).

Manipulate the total row to only sum the first row of every unique order in a list

This might be a strange question and not sure if it is possible to accomplish this with a Power BI table. My goal is to make the total row display the sum of the first row (Operation flag = 1) of every order in a list.
Logically the summarizing total row would produce the below result by summarizing all the rows in the "Manufactured Qty" column. (The below is just a manually created example in Excel to illustrate)
The desired DAX logic should instead produce the below result i.e. summarizing the quantity of every "Order no" with "Operation flag" equal to 1 in the total row.
Best regards,
Rubrix
One way to do this is to use a measure instead of the column. In this measure, use HASONEVALUE to check if the value is for a data row or for the totals row and either return the sum of all rows (for the normal case) or the sum of the rows where Operation flag = 1 (for the totals).
Manifactured Qty Measure =
var allRows = SUM('Table'[Manifactured Qty])
var firstOnly = CALCULATE(sum('Table'[Manifactured Qty]),'Table'[Operation flag] = 1)
RETURN IF(HASONEVALUE('Table'[Manifactured Qty]), allRows, firstOnly)

How to get total number in Power BI matrix rows

Here's a sample of raw data in the Power BI table.
I want to sum the numbers of Col D group by Col B and Col C and list them as an aggregate number in matrix rows. How can I get the desire layout like this? It seems easy but couldn't figure it out.
Thank you in advance
Forgot to mention Col C has more quarters than the listed. So the sum would go with the slicers outside.
You can add a calculated column to your table and use this in your row list in the matrix:
NewColumn = CALCULATE( SUM('Table'[COL D]) , ALLEXCEPT('Table', 'Table'[COL A],'Table'[COL B] ))

How to count number or rows in in one column, group by values in another column in Power BI

I have a table with two columns A, B.
Column A Column B
Fruit Apple
Fruit Orange
Fruit Pear
Veg Beans
Veg Potato
I need to count the number of occurrences of column B for each distinct value in Column A
Required Result:
Column A Occurence
Fruit 3
Veg 2
Is there any function I can use in DAX to get the required result?
You can use these measure in dax:
Occurence = CALCULATE(CALCULATE(COUNT(Table1[ColumnA]));ALLEXCEPT(Table1;Table1[ColumnA]))
And use a table visualization in Power BI with Column A and other column with "Occurence" to see the result.