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 reader,
A demo from what the data looks like:
ID Value YearMonth
CustomerA $50 202009
CustomerA $50 202008
CustomerA $50 202007
CustomerB $21 202007
CustomerB $21 202004
What I would like to do is add a column that returns value 1, based on the latest month (highest number), matching the same customer, as such:
ID Value YearMonth Indicator
CustomerA $50 202009 1
CustomerA $50 202008 0
CustomerA $50 202004 0
CustomerB $21 202001 1
CustomerB $21 201911 0
This way I can filter out duplicates in my report. Im trying to use the earlier() function, but do not know how to return on highest value. Please let me know if my request is possible.
Kind regards,
Daniël
Solved! Go to Solution.
@Anonymous , Try
new column = if([YearMonth] = maxx(filter(table, [ID] = earlier([ID])),[YearMonth]),1,0)
or
new measure = if(max(Table[YearMonth]) = maxx(filter(allselected(table), [ID] = max([ID])),[YearMonth]),1,0)
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a custom column with following m codes.
let
id=[ID],
maxyearmonth=List.Max(
Table.SelectRows(#"Changed Type",each [ID]=id)[YearMonth]
)
in
if [YearMonth]=maxyearmonth
then 1 else 0
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a custom column with following m codes.
let
id=[ID],
maxyearmonth=List.Max(
Table.SelectRows(#"Changed Type",each [ID]=id)[YearMonth]
)
in
if [YearMonth]=maxyearmonth
then 1 else 0
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymous , Try
new column = if([YearMonth] = maxx(filter(table, [ID] = earlier([ID])),[YearMonth]),1,0)
or
new measure = if(max(Table[YearMonth]) = maxx(filter(allselected(table), [ID] = max([ID])),[YearMonth]),1,0)
Awesome, that did the job!
Any chance I could do the same in Power Query?
I'd love to hear it!
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 |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |