Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Dear DAX Brains Trust!
I'm trying to write a column in DAX that returns the first value above 50% within a categorised cumulative column.
For context I've got a big dataset off all the postcodes around Australia and with each postcode comes an income category, 14 to be precise, thanks to the Australia Bureau of Statistics (ABS).
I've been through an arduous but insightful process via power query in which I have organised them by creating a list.generate function which has returned each income category within the postcode with cumulative running total of income % - Thanks to @RickdeGroot (BI Gorrilla) and possibly the GOAT of M code.
I've now got my data how I want it, and as a final step would like to create a measure or column. That returns the first value over 50% within the cumulative running for each postcode.
I'm a bit stumped at how I achieve this, I've tried RANKX & TOPN but with very little success.
Will post a screenshot of the data and attempted DAX code tomorrow. Any advice beforehand would be greatly appreciated.
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below, and I hope the below can provide some ideas on how to create a solution for your datamodel.
Income: =
SUM( Data[Income] )
Income cumulative ratio: =
VAR _runningtotal =
CALCULATE (
[Income:],
WINDOW (
1,
ABS,
0,
REL,
ADDCOLUMNS (
SUMMARIZE ( ALL ( Data ), PostCode[PostCode], Data[Customer] ),
"@income", [Income:]
),
ORDERBY ( [@income], ASC ),
KEEP,
PARTITIONBY ( PostCode[PostCode] )
)
)
VAR _allincomebypostcode =
CALCULATE ( [Income:], ALL ( Data[Customer] ) )
VAR _cumulativepercentage =
DIVIDE ( _runningtotal, _allincomebypostcode )
RETURN
_cumulativepercentage
First value above 50%: =
IF (
[Income cumulative ratio:]
= MINX (
FILTER (
ADDCOLUMNS ( ALL ( Data[Customer] ), "@ratio", [Income cumulative ratio:] ),
[@ratio] > 0.5
),
[@ratio]
),
[Income:]
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thanks for this, It's very helpful.
Your code seems to work and it is what I am looking for. However when I run it it returns all atribute values above 50%. Whilst I am only seeking the first value above 50% categorised by postcode. See screenshot below. I've underlined the postcode category types and the value I want it to return.
Hi,
Thank you for your message.
My solution was for writing calculated measures, not for calculated columns.
I am not 100% sure, but it might need to be written in a different way based on how your data model looks like.
Thanks.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
26 | |
21 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
19 | |
18 |