Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi All,
Below is a sample stand alone table that I have on BI.
The data comes from an Excel file so gets updated many times during the day.
I am trying to add a collumn (LAST RECORD) that identifies that latest time where the Sales Date and Machine Match.
So in the example below of the 3 records with Sales Date 26/06/2021 and Machine A1 what is the latest date/time ?
Any help or guidence appreciated as I have got so far with VAR statements as I can and still just cant crack it.
Thanks in anticipation.
Format of fields are as follows.
SALES DATE is Date format, Machine = Text and Date_Time = Date/Time format.
Sales Date | Machine | Date_Time | Last Record |
26/06/2021 | A1 | 25/06/2021 09:00 | |
26/06/2021 | A1 | 25/06/2021 12:40 | |
26/06/2021 | A1 | 25/06/2021 17:10 | YES |
26/06/2021 | A2 | 25/06/2021 19:50 | YES |
26/06/2021 | A2 | 25/06/2021 09:00 | |
27/06/2021 | A1 | 26/06/2021 14:50 | YES |
27/06/2021 | A1 | 26/06/2021 08:45 | |
27/06/2021 | A1 | 26/06/2021 12:51 | |
27/06/2021 | A2 | 26/06/2021 15:45 | YES |
27/06/2021 | A2 | 26/06/2021 08:43 | |
28/06/2021 | A1 | 27/06/2021 19:56 | YES |
28/06/2021 | A1 | 27/06/2021 07:45 | |
28/06/2021 | A2 | 27/06/2021 07:56 | YES |
28/06/2021 | A2 | 27/06/2021 06:45 | |
28/06/2021 | A3 | 26/06/2021 23:45 | |
28/06/2021 | A3 | 27/06/2021 19:45 | YES |
28/06/2021 | A3 | 27/06/2021 08:45 |
Solved! Go to Solution.
Last_Record_CC =
VAR __mch = SALES[Machine]
VAR __dt = SALES[Sales Date]
RETURN
IF(
SALES[Date_Time]
= MAXX(
FILTER( SALES, SALES[Machine] = __mch && SALES[Sales Date] = __dt ),
SALES[Date_Time]
),
"YES"
)
Bonus solution with Power Query
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
@Spudduk here is a DAX to add a column:
Last Col =
IF (
'Table'[Date_Time] = CALCULATE ( MAX ( 'Table'[Date_Time] ), ALLEXCEPT ( 'Table', 'Table'[Machine], 'Table'[Sales Date] ) ),
"Yes"
)
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Hi @Spudduk ,
you can do it like this:
Last Record =
VAR _MaxTime =
CALCULATE (
MAX ( 'Table'[Date_Time] ),
ALLEXCEPT ( 'Table', 'Table'[Sales Date], 'Table'[Machine] )
)
RETURN
IF ( MIN ( 'Table'[Date_Time] ) = _MaxTime, "Yes", "-" )
With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
WOW, never seen so many people answering the same comparatively simple question, in a way it is good, you get to see how other things and solve the problem but thinking from the OP perspective, must be very confusing seeing so many solutions, what to use and what to ignore?
Good luck @Spudduk
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi @Spudduk ,
you can do it like this:
Last Record =
VAR _MaxTime =
CALCULATE (
MAX ( 'Table'[Date_Time] ),
ALLEXCEPT ( 'Table', 'Table'[Sales Date], 'Table'[Machine] )
)
RETURN
IF ( MIN ( 'Table'[Date_Time] ) = _MaxTime, "Yes", "-" )
With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)
@Spudduk here is a DAX to add a column:
Last Col =
IF (
'Table'[Date_Time] = CALCULATE ( MAX ( 'Table'[Date_Time] ), ALLEXCEPT ( 'Table', 'Table'[Machine], 'Table'[Sales Date] ) ),
"Yes"
)
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Last_Record_CC =
VAR __mch = SALES[Machine]
VAR __dt = SALES[Sales Date]
RETURN
IF(
SALES[Date_Time]
= MAXX(
FILTER( SALES, SALES[Machine] = __mch && SALES[Sales Date] = __dt ),
SALES[Date_Time]
),
"YES"
)
Bonus solution with Power Query
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
105 | |
99 | |
99 | |
38 | |
37 |
User | Count |
---|---|
156 | |
121 | |
73 | |
73 | |
63 |