Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hello, I am trying to figure out how to implement with DAX
Consider the following matrix, where some column names start with e.g. “Field”
Date | Category | Type | Field1 | Field2 | Field3 | Field4 | Field5 | Field6 | Field7 |
dd/mm/yyyy | A | Peak | Value1 | ||||||
dd/mm/yyyy | B | OffPeak | Value2 | Value3 | Value33 | ||||
dd/mm/yyyy | C | Revenue | Value44 | Value15 | Value16 | Value18 | Value20 | Value22 | Value25 |
dd/mm/yyyy | C | Other | Value3 | Value25 | Value85 | Value45 | Value40 | Value41 | |
dd/mm/yyyy | A | Other | Value55 | Value56 | Value68 | Value78 | Value7 |
I would like to count for each Category A, B, C how many values are in the column named “Fieldxx” with xx that could vary from 1 to n.
In the example the result is
Category | Count |
A | 6 |
B | 3 |
C | 13 |
Thank you for your support. Bye
Solved! Go to Solution.
Hi @flyingfox ,
Thank you for your reply. You can still use this method, just change the selected columns in the step to the first three fixed columns and use the unpivot other column function, so that this method applies no matter how many FiledXXs come after that.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @flyingfox ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:
1. Open power query and select all the "Fieldxx" columns, right-click, and choose Unpivot Columns.
2.Close and apply and create a meaure
CountValuesByCategory =
SUMX(
VALUES('Table'[Category]),
CALCULATE(
COUNTROWS('Table'),
'Table'[Value] <> BLANK()
)
)
3.Final output
Thank you for your solution. Unpivoting the columns could work, but I should repeat manually these steps whenever I had to elaborate a new table with a different number of columns named “Fieldxx”. Do you have any other suggestions in order to avoid to execute unpivot specific columns?
Hi @flyingfox ,
Thank you for your reply. You can still use this method, just change the selected columns in the step to the first three fixed columns and use the unpivot other column function, so that this method applies no matter how many FiledXXs come after that.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
33 | |
16 | |
13 | |
10 | |
8 |
User | Count |
---|---|
59 | |
20 | |
12 | |
11 | |
10 |