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

LOD Dates compare previous week to current week

Is there a way we can do this in Power BI?

 
Laedays_0-1623932265915.png

 

My goal is to have a formula that will always determine the 'Current Week' and the 'Previous Week', the rest will show null values.

 

Is that possible in Power BI?

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

You can create a calculated column as below:

Week = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Data'[Last Update Date] ), ALL ( 'Data' ) )
VAR _secondmaxdate =
    CALCULATE (
        MAX ( 'Data'[Last Update Date] ),
        FILTER ( 'Data', 'Data'[Last Update Date] < _maxdate )
    )
RETURN
    IF (
        'Data'[Last Update Date] = _maxdate,
        "Current Week",
        IF ( 'Data'[Last Update Date] = _secondmaxdate, "Previous Week", BLANK () )
    )

You can also create a measure as below with similar formula:

Measure = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Data'[Last Update Date] ), ALLSELECTED(  'Data' ) )
VAR _secondmaxdate =
    CALCULATE (
        MAX ( 'Data'[Last Update Date] ),
        FILTER ( ALLSELECTED('Data'), 'Data'[Last Update Date] < _maxdate )
    )
RETURN
    IF (
        SELECTEDVALUE('Data'[Last Update Date]) = _maxdate,
        "Current Week",
        IF (SELECTEDVALUE('Data'[Last Update Date]) = _secondmaxdate, "Previous Week", BLANK () )
    )

yingyinr_1-1624268585267.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
selimovd
Super User
Super User

Hey @Anonymous ,

 

that is possible with a calculated column. You just have to compare the weeknumber of the column to the today's week number.

Try the following formula:

Week =
VAR vCurrentWeek = WEEKNUM( TODAY() )
RETURN
    SWITCH(
        WEEKNUM( myTable[Date] ),
        vCurrentWeek, "Current Week",
        vCurrentWeek - 1, "Previous Week",
        BLANK()
    )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

Hi, i tried to use the formula you said but it's not giving me the expected output. Please see below:

 

Laedays_0-1623997892389.png

 

The logic i need is to get the "current" if it's the latest date, then get the "previous" if it's less than the latest date then the rest will be null.

 

 

 

Hi @Anonymous ,

You can create a calculated column as below:

Week = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Data'[Last Update Date] ), ALL ( 'Data' ) )
VAR _secondmaxdate =
    CALCULATE (
        MAX ( 'Data'[Last Update Date] ),
        FILTER ( 'Data', 'Data'[Last Update Date] < _maxdate )
    )
RETURN
    IF (
        'Data'[Last Update Date] = _maxdate,
        "Current Week",
        IF ( 'Data'[Last Update Date] = _secondmaxdate, "Previous Week", BLANK () )
    )

You can also create a measure as below with similar formula:

Measure = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Data'[Last Update Date] ), ALLSELECTED(  'Data' ) )
VAR _secondmaxdate =
    CALCULATE (
        MAX ( 'Data'[Last Update Date] ),
        FILTER ( ALLSELECTED('Data'), 'Data'[Last Update Date] < _maxdate )
    )
RETURN
    IF (
        SELECTEDVALUE('Data'[Last Update Date]) = _maxdate,
        "Current Week",
        IF (SELECTEDVALUE('Data'[Last Update Date]) = _secondmaxdate, "Previous Week", BLANK () )
    )

yingyinr_1-1624268585267.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you!

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.