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.
I'm running into an issue with grouping data - I'd like to take the chronological order into account and not sure if it's possible. For instance, with the below data, when I group by amount and use min date it groups all amounts together, regarldess of date, which I get is supposed to happen. What I'd like to have happen, is have it go through the data chronologically and incorporate the date when it groups - see the second table below. Is it possible to do this in Power Query?
Date | Amount |
1/1/2020 | 1000 |
2/1/2020 | 1500 |
3/1/2020 | 1500 |
4/1/2020 | 1000 |
5/1/2020 | 1500 |
6/1/2020 | 1500 |
Desired Result | Actual Result | |||
First Date | Amount | Min Date | Amount | |
1/1/2020 | 1000 | 1/1/2020 | 1000 | |
2/1/2020 | 1500 | 2/1/2020 | 1500 | |
4/1/2020 | 1000 | |||
5/1/2020 | 1500 |
Solved! Go to Solution.
Hi @mterry ,
You can create a calculated column as below to achieve it:
First Date =
VAR predate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER ( ALL ( 'Table' ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
)
VAR predAmount =
CALCULATE (
MAX ( 'Table'[Amount] ),
FILTER ( ALL ( 'Table' ), 'Table'[Date] = predate )
)
RETURN
IF ( predAmount <> [Amount], 'Table'[Date] )
It also can be achieved it by creating a measure, you can get all details in this sample pbix file.
Best Regards
Rena
Hi @mterry ,
You can create a calculated column as below to achieve it:
First Date =
VAR predate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER ( ALL ( 'Table' ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
)
VAR predAmount =
CALCULATE (
MAX ( 'Table'[Amount] ),
FILTER ( ALL ( 'Table' ), 'Table'[Date] = predate )
)
RETURN
IF ( predAmount <> [Amount], 'Table'[Date] )
It also can be achieved it by creating a measure, you can get all details in this sample pbix file.
Best Regards
Rena
Thank you both, that helped
@mterry , try like with a date table
if(sum(table[Amount])- CALCULATE(sum(table[Amount]),PREVIOUSDAY(Date[Date]))=0, blank(),sum(table[Amount]))
or
sumx(filter(Summarize(Date,Date[Date],"_1",sum(table[Amount]),"_2", CALCULATE(sum(table[Amount]),PREVIOUSDAY(Date[Date]))),[_1]<>[_2]),[_1])
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...
Appreciate your Kudos.
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 |
---|---|
113 | |
100 | |
78 | |
76 | |
52 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |