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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Quazanic
Frequent Visitor

Reference Date to monitor just the last condition before that

Hi,

 

I have a table in PowerBI (from sharepoint list), includes columns: Name, Status and Date.
Every person has more rows based on their condition in time.
There is no shorting on columns, maybe the Date.

 

Task:
If I define a reference date, best would be a slicer; then the function is choosing the row pro Name where the date is the closest one to the reference date, but equal or before that.
If one of the chosen row includes "no" Status, then it needs to be hidden, it doesn't matter that the Name has a "yes" Status earlier.

  • (So I dont need just the "yes" status will be monitored and the closest date will be shown - it would be too easy.)

 

In MS Access I created a frontend and prepared a query with the function above, working well with different reference date, this function should be implemented in powerBI visual table.

Date in mm/dd/yyyy, and 3 examples how it should work: 

 

PowerBI_DataOnTime.jpg

I hope you can help me

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

Hi @Quazanic ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a date dimension table (Please DO NOT create any relationship between the fact table and date dimension table)

yingyinr_2-1678861933410.png

2. Create a measure as below 

Flag = 
VAR _seldate =
    SELECTEDVALUE ( 'Date'[Date] )
VAR _seltdate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _selname =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _selstatus =
    SELECTEDVALUE ( 'Table'[Status] )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Name] = _selname
                && 'Table'[Date] <= _seldate
        )
    )
RETURN
    IF ( _seltdate = _maxdate && _selstatus = "yes", 1, 0 )

3. Create a visual and apply the visual-level filter on the visual with the condition(Flag is 1)

yingyinr_3-1678862017057.png

 

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And 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

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Quazanic ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a date dimension table (Please DO NOT create any relationship between the fact table and date dimension table)

yingyinr_2-1678861933410.png

2. Create a measure as below 

Flag = 
VAR _seldate =
    SELECTEDVALUE ( 'Date'[Date] )
VAR _seltdate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _selname =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _selstatus =
    SELECTEDVALUE ( 'Table'[Status] )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Name] = _selname
                && 'Table'[Date] <= _seldate
        )
    )
RETURN
    IF ( _seltdate = _maxdate && _selstatus = "yes", 1, 0 )

3. Create a visual and apply the visual-level filter on the visual with the condition(Flag is 1)

yingyinr_3-1678862017057.png

 

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And 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.

Many thanks for your description and the attached file helps a lot.

Quazanic
Frequent Visitor

I create a measure:

Max Date =

CALCULATE(MAXX(FILTER(table, table[Date]), table[Date]), ALL(table[Status]))

 

In visual table I put Name, Max Date, Status

 

I can use a slicer, and the table working but there is an interesting failure. 

If the closest Date before the Reference Date has "no" Status, then this row is duplicated with a "yes" Staus as well; and what is really strange that this duplicated fake row has same Date what is belong to the "no" Status

 

How I could eliminate the fake "yes" rows?

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.