Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Employee | Sales | Lag | LagGroup |
Billy | 1 | ||
Billy | 2 | 1 | 1 |
Billy | 3 | 2 | 2 |
Bobby | 5 | 3 | |
Bobby | 10 | 5 | 5 |
Bobby | 15 | 10 | 10 |
I know it's fairly easy to generate the Lag column shown above, based off of the Sales column. Instead, can I first group by Employee and then add the custom LagGroup column, as shown above? If you notice, Bobby's first LagGroup is blank, as the intent is to group by employee, evaluate lags, and not pull in lag values from other employees. What power query or what DAX do I need to do? This is all done in a dataflow if that matters.
Solved! Go to Solution.
Hi @calcstuff ,
You can try this method:
In the Power Query, you can add a index column:
Then new a column:
LagGroup =
VAR _index =
CALCULATE (
MAX ( 'Table'[Index] ),
FILTER (
'Table',
[Employee] = EARLIER ( 'Table'[Employee] )
&& [Index] < EARLIER ( 'Table'[Index] )
)
)
RETURN
CALCULATE ( MAX ( 'Table'[Sales] ), FILTER ( 'Table', [Index] = _index ) )
The result is:
Hope these help you.
Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @calcstuff ,
You can try this method:
In the Power Query, you can add a index column:
Then new a column:
LagGroup =
VAR _index =
CALCULATE (
MAX ( 'Table'[Index] ),
FILTER (
'Table',
[Employee] = EARLIER ( 'Table'[Employee] )
&& [Index] < EARLIER ( 'Table'[Index] )
)
)
RETURN
CALCULATE ( MAX ( 'Table'[Sales] ), FILTER ( 'Table', [Index] = _index ) )
The result is:
Hope these help you.
Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
45 | |
34 | |
32 | |
25 | |
23 |
User | Count |
---|---|
34 | |
33 | |
21 | |
20 | |
15 |