Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
bajimmy1983
Helper V
Helper V

How to show LASTNONBLANK Date from LASTDAST

Hi all, how are you? 

 

Maybe this DAX is simple, but I've tried lot's of thing and failed. Until get here I usually really try hard! Do you know how to accomplish this? Could you help? I don't want to do it adding Custom Columns in dataset. I immagine it can be done using Measures instead.

 

So, I have a simple fTable like below and I just want to calculate Last Week based on fTable given dates (not contiguous date) . I can do it hard coding the numbers of days inside DATEADD because I know people are feeding it every Monday, but I want to replace "-7" inside DATEADD for an automatic number of days in the past. So, DAX has to be intelligent enough to know how many days it has to go back. Even if I know people updates data every Monday I want to grant that when someone forgets, DAX will use the correct number to go back. 

 

eg: If I didn't have 21/10/2019... So, DAX has to know last day before 28/10/2019 is 14/10/2019 and then go back 14 days instead of just 7 giving us a "Custom Last Week". 

 

Measure

 

DAX LW = 
IF (
    [Total de Horas Tipo de Saldo] <> BLANK ();
    CALCULATE ( [Total de Horas Tipo de Saldo]; DATEADD ( 'Date'[Date]; -7; DAY ) )
)

 

 

Table Visual: 

DESIRED OUTCOMEDESIRED OUTCOME

Thanks a lot to everyone in advance and have a nice week! 🙂 

Jaderson Almeida
Business Coordinator
1 ACCEPTED SOLUTION

Hi,

Write these measures

Previous date on which hours were booked = if(ISBLANK([Total de Horas]),BLANK(),CALCULATE(LASTNONBLANK('Date'[Date],[Total de Horas]),DATESBETWEEN('Date'[Date],MINX(ALL('Date'[Date]),'Date'[Date]),MAX('Date'[Date])-1)))
Measure = if(ISBLANK([Previous date on which hours were booked]),BLANK(),CALCULATE([Total de Horas],DATESBETWEEN('Date'[Date],[Previous date on which hours were booked],[Previous date on which hours were booked])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where I can download your PBI file.  In your file, ensure that there is no data for October 21.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur , thanks for replying 🙂

 

Please, you can access at: https://1drv.ms/u/s!Aq2_y0xKTrAvg4wpaKOeUZmnBG4VmQ?e=o0E7l3

 

Best,

Jimmy

Jaderson Almeida
Business Coordinator

Hi,

Write these measures

Previous date on which hours were booked = if(ISBLANK([Total de Horas]),BLANK(),CALCULATE(LASTNONBLANK('Date'[Date],[Total de Horas]),DATESBETWEEN('Date'[Date],MINX(ALL('Date'[Date]),'Date'[Date]),MAX('Date'[Date])-1)))
Measure = if(ISBLANK([Previous date on which hours were booked]),BLANK(),CALCULATE([Total de Horas],DATESBETWEEN('Date'[Date],[Previous date on which hours were booked],[Previous date on which hours were booked])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur, hi again! 

 

It worked pretty well. I just "broke" your two measures into pieces (VARs) in order to understand the flow and then adapted it to mine. Now I got it and can see entire scenario! 😍😎

 

Total de Horas Tipo de Saldo LW = 
VAR _TestLASTNONBLANK =
    LASTNONBLANK ( 'Date'[Date]; [Total de Horas Tipo de Saldo] )
VAR _TestMINX =
    MINX ( ALL ( 'Date'[Date] ); 'Date'[Date] )
VAR _TestMAX =
    MAX ( 'Date'[Date] ) - 1
VAR _PreviousDate =
    IF (
        ISBLANK ( [Total de Horas Tipo de Saldo] );
        BLANK ();
        CALCULATE (
            LASTNONBLANK ( 'Date'[Date]; [Total de Horas Tipo de Saldo] );
            DATESBETWEEN (
                'Date'[Date];
                MINX ( ALL ( 'Date'[Date] ); 'Date'[Date] );
                MAX ( 'Date'[Date] ) - 1
            )
        )
    )
RETURN
    IF (
        _PreviousDate <> BLANK ();
        CALCULATE (
            [Total de Horas Tipo de Saldo];
            DATESBETWEEN ( 'Date'[Date]; _PreviousDate; _PreviousDate )
        )
    )

 

Thank you so much once again.

Jaderson Almeida
Business Coordinator

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

That’s great. I’ll apply it ASAP and let you know.

Thanks again so much for your super support!
Jaderson Almeida
Business Coordinator

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.