Forum Discussion
[Help] Count with condition across column
- 9 years ago
Hi there,
Happy to help! So DAX works best calculating rows within a column. It's trickier when you have values for a customer split across columns, however there is a wonderful feature in "Get & Transform (Power Query)" that lets you UnPivot columns onto rows. If you're able to do that in Power Query first then creating the DAX measure is MUCH easier. Your table would look like the one pictured below following the "UnPivoting".
With the table in this structure you would create two DAX measures: [Total Volume] & [# of Months w/ Sales], with the idea that DAX measures are a lot like lego blocks, one building on the other. The [Total Volume] measure will be referenced in [# of Months w/ Sales] which will count the months of sales.
[Total Volume] Formula:
= SUM( 'Table'[Volume] )
[# of Months w/ Sale] Formula:
= CALCULATE ( DISTINCTCOUNT ( 'Table'[Volume Month] ), FILTER ( 'Table', [Total Volume] > 0 ) )I'm happy to send you over the PBI file with these transformations/formulas as well if you'd like.
- 9 years ago
Have a play with this in the Query Editor
Highlight the three columns you want to "unpivot" then right click and select Unpivot columns
Turned into this....
Hi there,
Happy to help! So DAX works best calculating rows within a column. It's trickier when you have values for a customer split across columns, however there is a wonderful feature in "Get & Transform (Power Query)" that lets you UnPivot columns onto rows. If you're able to do that in Power Query first then creating the DAX measure is MUCH easier. Your table would look like the one pictured below following the "UnPivoting".
With the table in this structure you would create two DAX measures: [Total Volume] & [# of Months w/ Sales], with the idea that DAX measures are a lot like lego blocks, one building on the other. The [Total Volume] measure will be referenced in [# of Months w/ Sales] which will count the months of sales.
[Total Volume] Formula:
= SUM( 'Table'[Volume] )
[# of Months w/ Sale] Formula:
=
CALCULATE (
DISTINCTCOUNT ( 'Table'[Volume Month] ),
FILTER ( 'Table', [Total Volume] > 0 )
)I'm happy to send you over the PBI file with these transformations/formulas as well if you'd like.
Thanks Reid,
Actually I have more than 36 month column and million of rows. But I will have a try since this is better than create a column function.. ,
Could you please kindly send me the file you mentioned as well :)
Highly appreciate your quick support,
Cheers,
- Phil_Seamark9 years agoMicrosoft Employee
Have a play with this in the Query Editor
Highlight the three columns you want to "unpivot" then right click and select Unpivot columns
Turned into this....