Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello
I'm facing some issues finding way to solve how to create a column that does the following:
A. Count distinct values according to a category, for example, count of different ids for pants, sweaters and t-shirts.
B. Then take every distinct value per category and multiply by a fixed value like pants = 5, sweaters= 2, and t shirts=1
C. Count distinct values of all categories.
D. Take point C and multiply by a fixed value according to a category like in B.
E. Take the product of B/D and multiply by 100.
Is this possible? I have accomplished to do so in several measures but I can not figure out how to create a column with the
Solved! Go to Solution.
Hi @chela199 ,
Please try this:
Column =
VAR _category = 'Table'[Category]
VAR _A =
CALCULATE (
DISTINCTCOUNT ( 'Table'[ID] ),
FILTER ( ALL ( 'Table' ), 'Table'[Category] = _category )
)
VAR _B =
SUMX (
VALUES ( 'Table'[Category] ),
SWITCH ( _category, "pants", _A * 5, "sweaters", _A * 2, "t-shirts", _A )
)
VAR _C =
DISTINCTCOUNT ( 'Table'[ID] )
VAR _D =
SUMX (
VALUES ( 'Table'[Category] ),
SWITCH ( _category, "pants", _C * 5, "sweaters", _C * 2, "t-shirts", _C )
)
VAR _E =
DIVIDE ( _B, _D ) * 100
RETURN
_E
You can change the variable name after RETURN to check if the calculation at each step meets your needs. If this does not work, consider providing sample data and expected output.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
Hi @chela199 ,
Please try this:
Column =
VAR _category = 'Table'[Category]
VAR _A =
CALCULATE (
DISTINCTCOUNT ( 'Table'[ID] ),
FILTER ( ALL ( 'Table' ), 'Table'[Category] = _category )
)
VAR _B =
SUMX (
VALUES ( 'Table'[Category] ),
SWITCH ( _category, "pants", _A * 5, "sweaters", _A * 2, "t-shirts", _A )
)
VAR _C =
DISTINCTCOUNT ( 'Table'[ID] )
VAR _D =
SUMX (
VALUES ( 'Table'[Category] ),
SWITCH ( _category, "pants", _C * 5, "sweaters", _C * 2, "t-shirts", _C )
)
VAR _E =
DIVIDE ( _B, _D ) * 100
RETURN
_E
You can change the variable name after RETURN to check if the calculation at each step meets your needs. If this does not work, consider providing sample data and expected output.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
Hi @chela199,
You can use EARLIER function to get the count based on different category. With that you would get a column that shows count of all IDs in pants category for all rows with pants and so on for all category. You can then multiply these values with your fixed value using IF conditions. Once you have B and D, division should be easy.
Mark this post as a solution if that works for you!
Check out this blog of mine: How to Export Telemetry Data from Azure IoT Central into Power BI
User | Count |
---|---|
93 | |
86 | |
78 | |
72 | |
66 |
User | Count |
---|---|
115 | |
106 | |
85 | |
65 | |
64 |