Forum Discussion
What's the DAX syntax equivalent to a sql windowing
Hi all,
I'm stuck trying to figure out the DAX formula to solve this problem :
I need to filter a table based on the latest StatusCode at a given date.
Here's a sample of my Positions table :
| PositionId | PositionDate | ContainerId | StatusCode |
| 34408 | 08/03/2018 | 1 | RCVE |
| 95676 | 10/04/2018 | 1 | RCVF |
| 100525 | 12/04/2018 | 1 | SUBL |
| 101685 | 21/05/2018 | 1 | RTSL |
| 111024 | 23/05/2018 | 1 | RCVF |
| 585046 | 15/01/2019 | 2 | RCVE |
| 595659 | 22/01/2019 | 2 | SUBL |
| 622710 | 06/02/2019 | 2 | RTSL |
| 628154 | 08/02/2019 | 2 | DVSF |
| 255695 | 05/07/2018 | 3 | TRLE |
| 294286 | 26/07/2018 | 3 | SUBL |
| 341214 | 22/08/2018 | 3 | RTSL |
| 355613 | 30/08/2018 | 3 | OTSH |
| 89795 | 06/04/2018 | 4 | DVSE |
| 95552 | 10/04/2018 | 4 | OTSH |
| 97635 | 11/04/2018 | 4 | SUBL |
| 79650 | 26/03/2018 | 5 | RCVE |
| 79657 | 27/03/2018 | 5 | SUBL |
| 202818 | 05/06/2018 | 5 | RTSL |
| 202819 | 06/06/2018 | 5 | TRLE |
| 64422 | 22/03/2018 | 6 | RCVF |
| 193698 | 27/05/2018 | 6 | SUBL |
| 196336 | 03/06/2018 | 6 | LVSF |
| 206919 | 07/06/2018 | 6 | DVSF |
I need to find all the ContainerIds with a StatusCode of SUBL up to a certain date. For instance :
- on 01/04/2018, the results should be :
| PositionId | PositionDate | ContainerId | StatusCode |
| 79657 | 27/03/2018 | 5 | SUBL |
- on 01/05/2018, I should find :
| PositionId | PositionDate | ContainerId | StatusCode |
| 79657 | 27/03/2018 | 5 | SUBL |
| 97635 | 11/04/2018 | 4 | SUBL |
| 100525 | 12/04/2018 | 1 | SUBL |
- and on 01/02/2019 I should find
| PositionId | PositionDate | ContainerId | StatusCode |
| 79657 | 27/03/2018 | 5 | SUBL |
| 97635 | 11/04/2018 | 4 | SUBL |
| 100525 | 12/04/2018 | 1 | SUBL |
| 193698 | 27/05/2018 | 6 | SUBL |
| 294286 | 26/07/2018 | 3 | SUBL |
| 595659 | 22/01/2019 | 2 | SUBL |
It seems to me to be the equivalent of a SQL Windowing function to which I'd pass a date parameter and that would iterate over the container ids to find the StatusCode for this MAX(Date) and just return all the ContainerIds with this StatusCode up to this date.
But I'm stuck in DAX...
Any help by you DAX Gurus out there would be greatly appreciated...
17 Replies
- Nathaniel_C
Community Champion
Hi franck_axires ,
Just to be sure, you are doing this as a visualization in PBI?I
Nathaniel- franck_axiresFrequent Visitor
Hi Nathaniel_C
Thanks for your interest !
The table is only a sample. I'll make nice pie/bar/you-name-it charts for my client.
- Nathaniel_C
Community Champion
Hi franck_axires ,
A quick data table placed in a Table visualization. Then use filters date is on or before, and Status Code for what is needed.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel- franck_axiresFrequent Visitor
Hi Nathaniel_C
Thanks for your reply.
I also need to create a measure that will be used to calculate ratios.
That's why I need the DAX formula...
If you have any clues...
Thanks again !
- Nathaniel_C
Community Champion
Hi franck_axires ,
You need a measure to help calculate ratios, but what you are showing us is a table. What two numbers do you need for the ratio?
We can do tables in the power query editor, or in the Power BI, but what a measure is doing is filtering the rows and returning a value that can go into 1 cell. Like the sum of a column.
So looking for more info here. Thanks!
==============Get status code = CALCULATE(max(Positions[StatusCode]),Positions[PositionDate]=DATE(2018,5,21)) We can do with parameter.And there is DATESBETWEEN() which we can probably use.
Nathaniel