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
Anonymous
Not applicable

How to get previous date from fact table if max date is weekend in power bi

HI Team

can you please let me know i just need to sum of Total Length as per max date and Previous date

SPTotal LengthDate
A18/07/2021
B28/07/2021
C38/07/2021
A49/07/2021
B59/07/2021
C69/07/2021
A712/07/2021
B812/07/2021
C912/07/2021

 

Like if I use max(Date)-1 it shows 11/7/21 which is weekend then it should select 9/7/21 for filtering.

I am using this meassure

Previous_Total_Length =
CALCULATE(
[TTD],
FILTER(ALL(Sheet1[Download Date]),
Sheet1[Download Date]= MAX(Sheet1[Download Date])-3
)
)

so if MAX(Sheet1[Download Date])-1 is weekend then i have to do -3 and if not then -1. but i dont want manually change -3 and -1. 

can anyone help me out.

heaps thanks

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

You asked a question in Power Query, but you need a DAX measure, right? Is your Sheet1 the same fact table as your sample data? Try to identify weekday first

Previous_Total_Length =
VAR CurDate =
    MAX ( Sheet1[Download Date] )
VAR CurDay =
    WEEKDAY ( CurDate, 2 )
VAR PreDate =
    SWITCH (
        TRUE (),
        CurDay = 1, CurDate - 3,
        CurDay = 7, CurDate - 2,
        CurDate - 1
    )
RETURN
    CALCULATE (
        [TTD],
        FILTER ( ALL ( Sheet1[Download Date] ), Sheet1[Download Date] = PreDate )
    )

 

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

You asked a question in Power Query, but you need a DAX measure, right? Is your Sheet1 the same fact table as your sample data? Try to identify weekday first

Previous_Total_Length =
VAR CurDate =
    MAX ( Sheet1[Download Date] )
VAR CurDay =
    WEEKDAY ( CurDate, 2 )
VAR PreDate =
    SWITCH (
        TRUE (),
        CurDay = 1, CurDate - 3,
        CurDay = 7, CurDate - 2,
        CurDate - 1
    )
RETURN
    CALCULATE (
        [TTD],
        FILTER ( ALL ( Sheet1[Download Date] ), Sheet1[Download Date] = PreDate )
    )

 

Anonymous
Not applicable

HI Vera_33, I really appriciate your  support. to get this to be done I strugged a lot. now get sorted. Heaps thanks

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.

Top Solution Authors
Top Kudoed Authors