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.
Hi All,
Can someone suggest me a DAX measure for the below input data which will allow me to seggregate the LastAttendanceDate column and SecondLastAttendanceDate column andLastAttendanceDateLocation column and SecondLastAttendanceDateLocation column from my input datasource based on the flag 1 and 2 values in flag column. flag 1 denotes last attendance date column and lastattendancedate, while flag 2 denotes secondlast attendance date column and second last attendance date location
We can easily achieve this using conditional column concept but I am using direct query for SQL datasource so it throws error for conditional column.
Please suggest how can i seggregate this using DAX measure?
I tried uisng SWITCH case and IF statements in DAX, no luck as it didnt fetch the results since it didnt allow me to pass column values.Only scalar values allowed in IF and switch.I am not sure how can I handle this
Input sample datasource:
StudentID | StudentName | AttendanceDate | StudentType | location | flag |
100 | Mary | 02-05-2011 10:45 | Fulltime | Gate1 | 2 |
100 | Mary | 02-05-2011 12:45 | Fulltime | Gate2 | 1 |
100 | Mary | 02-05-2011 09:45 | Fulltime | Gate3 | |
100 | Mary | 02-05-2011 08:45 | Fulltime | Gate3 | |
101 | John | 02-05-2011 10:59 | Part Time | Gate2 | 2 |
101 | John | 02-05-2011 12:56 | Part Time | Gate1 | 1 |
101 | John | 02-05-2011 09:55 | Part Time | Gate5 | |
101 | John | 02-05-2011 06:35 | Part Time | Gate1 | |
101 | John | 02-05-2011 10:48 | Part Time | Gate3 | |
102 | Tom | 03-05-2011 09:55 | Part Time | Gate3 | |
102 | Tom | 03-05-2011 10:48 | Part Time | Gate1 | 2 |
102 | Tom | 03-05-2011 09:55 | Part Time | Gate1 | |
102 | Tom | 03-05-2011 10:47 | Part Time | Gate1 | |
102 | Tom | 03-05-2011 13:48 | Part Time | Gate2 | 1 |
Expected: output should look like below
P.S: My datasource is SQL and I use direct query
regards
Sameer
Solved! Go to Solution.
Hi @deb_power123 ,
Create 4 measures as below:
LastAttendanceDate = CALCULATE(MAX('Table'[AttendanceDate]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=1))
LastAttendanceDateLocation = CALCULATE(MAX('Table'[location]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=1))
SecondLastAttendanceDate = CALCULATE(MAX('Table'[AttendanceDate]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=2))
SecondLastAttendanceDateLocation = CALCULATE(MAX('Table'[location]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=2))
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Hi @deb_power123 ,
Create 4 measures as below:
LastAttendanceDate = CALCULATE(MAX('Table'[AttendanceDate]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=1))
LastAttendanceDateLocation = CALCULATE(MAX('Table'[location]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=1))
SecondLastAttendanceDate = CALCULATE(MAX('Table'[AttendanceDate]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=2))
SecondLastAttendanceDateLocation = CALCULATE(MAX('Table'[location]),FILTER(ALL('Table'),'Table'[StudentID]=MAX('Table'[StudentID])&&'Table'[flag]=2))
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Thankyou , awesome approach
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 |
---|---|
97 | |
95 | |
80 | |
77 | |
66 |
User | Count |
---|---|
130 | |
106 | |
105 | |
86 | |
72 |