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

IF current week is blank show prior week and if prior week is blank so Not Available

Hi All,

 

I am having difficulty finding a solution to a simple logic measure. The measure will be placed in the KPI visual. The logic is as follows:

 

Two measures:

Current Week

Prior Week

 

Logic:

If the current week's results are blank, show the prior week's results. If the prior week's results are blank, show "Not Available".

 

The reason the current week's results would be blank is because a portion of our data is not updated until the end of the week and everything else is updated at the beginning of the week. The reason the prior week would be blank is again the same reason except the lag between updates may move into following week.

 

Thank you!

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

Measure = 
VAR _selweek =
    SELECTEDVALUE ( 'Date'[Week] )
VAR _sales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        WEEKNUM ( 'Table'[Date], 2 ) = SELECTEDVALUE ( 'Date'[Week] )
    )
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( ALL ( 'Date' ), NOT ( ISBLANK ( _sales ) ) )
    )
VAR _pwsales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALLSELECTED ( 'Table' ), WEEKNUM ( 'Table'[Date], 2 ) = _selweek - 1 )
    )
RETURN
    IF (
        _selweek < WEEKNUM ( _mindate, 2 ),
        BLANK (),
        IF (
            ISBLANK ( _sales ) && ISBLANK ( _pwsales ),
            "Not Available",
            IF ( ISBLANK ( _sales ), _pwsales, _sales )
        )
    )

yingyinr_1-1666327706191.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

Measure = 
VAR _selweek =
    SELECTEDVALUE ( 'Date'[Week] )
VAR _sales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        WEEKNUM ( 'Table'[Date], 2 ) = SELECTEDVALUE ( 'Date'[Week] )
    )
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( ALL ( 'Date' ), NOT ( ISBLANK ( _sales ) ) )
    )
VAR _pwsales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALLSELECTED ( 'Table' ), WEEKNUM ( 'Table'[Date], 2 ) = _selweek - 1 )
    )
RETURN
    IF (
        _selweek < WEEKNUM ( _mindate, 2 ),
        BLANK (),
        IF (
            ISBLANK ( _sales ) && ISBLANK ( _pwsales ),
            "Not Available",
            IF ( ISBLANK ( _sales ), _pwsales, _sales )
        )
    )

yingyinr_1-1666327706191.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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.
amitchandak
Super User
Super User

@Anonymous , you have few columns in date table

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

and then you can have measure like
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

 

The final measure can be 

 

if(isblank([This Week]), if(isblank([Last week]), "Not Avaiable", [Last Week]&""), [This Week]&"")

 

But this will make your measure as text measure

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