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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Delphia
Advocate II
Advocate II

FILTER by previous available date

Hi dear community,

I need your help with filtering data. I need to create a measure that will calculate total amount for the previous date in table.

I have the following measure:

Totals Yesterday = CALCULATE(
                                                  SUM(table[sale]),
                                                  FILTER(
                                                             'Date', 'Date'[Date] = TODAY () - 1
                                                   )
                                )
 
It works well. The problem appears when I don't have values for Yesterday but the last values were added several days ago.
In this case I want to show data for the previous available date in table
 
 
I would appreciate your help!
1 ACCEPTED SOLUTION
Delphia
Advocate II
Advocate II

Solved with the following measure, proposed by @Anonymous in another topic

Previous Value  =
VAR CurrentDate = MAX(cleaned_row_count[Date])
VAR ClientID = MAX('table'[id])
VAR PreviousDate = CALCULATE(MAX(cleaned_row_count[Date]),ALL('Date'[Date]),ALL(cleaned_row_count[Date]),FILTER('Date',[Date]<CurrentDate))
VAR Result = CALCULATE(SUM(cleaned_row_count[Number of Rows]),ALL('Date'[Date]),ALL(cleaned_row_count[Date]),FILTER('Date',[Date]=PreviousDate))
RETURN Result

View solution in original post

9 REPLIES 9
Delphia
Advocate II
Advocate II

Solved with the following measure, proposed by @Anonymous in another topic

Previous Value  =
VAR CurrentDate = MAX(cleaned_row_count[Date])
VAR ClientID = MAX('table'[id])
VAR PreviousDate = CALCULATE(MAX(cleaned_row_count[Date]),ALL('Date'[Date]),ALL(cleaned_row_count[Date]),FILTER('Date',[Date]<CurrentDate))
VAR Result = CALCULATE(SUM(cleaned_row_count[Number of Rows]),ALL('Date'[Date]),ALL(cleaned_row_count[Date]),FILTER('Date',[Date]=PreviousDate))
RETURN Result
amitchandak
Super User
Super User

@Delphia , With help from date table

 

max date

Measure =
var _max = maxx(allselected('Date'), Date[Date])
return
CALCULATE([sales],filter('Date', 'Date'[Date] =_max))

 

 

 

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you so much for your answer.

It doesn't work for me. Let me precise a little bit my question. My scheme looks like: 

scheme.jpg

Above in my question I replaced "Number of Rows" by "Sale", sorry.

I created a measure using your patern and get the following:

 
Last Day Non Continuous =
                                         CALCULATE(
                                                  SUM(cleaned_row_count[Number of Rows]),
                                                  FILTER(
                                                            ALLSELECTED('Date'),
                                                            'Date'[Date] = MAXX(
                                                                          FILTER(
                                                                          ALLSELECTED('Date'),
                                                                         'Date'[Date] < MAX('Date'[Date])
                                                                          ),
                                                            'Date'[Date]
                                                            )
                                                  )
                                       )
Nevertheless, my table shows empty values for Last Day Non Continuous.
table.jpg
 
For Total Rows Today column I use the following measure:
Total Rows Today =
var total = CALCULATE(sum(cleaned_row_count[Number of Rows]),
            FILTER(cleaned_row_count, cleaned_row_count[Date]= TODAY()))
return
IF(ISBLANK(total), 0, total)
 
Date table is autogenerated: 
Date = CALENDARAUTO()
So maximum value is the end of this year: 2021-12-31
 
Thank you in advance for your help! 

@Delphia 

This will work:

Previous Date rows =
VAR PrevDate =
    MAXX (
        FILTER (
            ALL ( 'Date' ),
            'Date'[Date] < MAX ( 'Date'[Date] )
                && NOT ( ISBLANK ( [Number of rows] ) )
        ),
        'Date'[Date]
    )
RETURN
    IF (
        ISBLANK ( [Number of rows] ),
        BLANK (),
        CALCULATE (
            [Number of rows],
            FILTER ( ALL ( 'Date' ), 'Date'[Date] = PrevDate )
        )
    )




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you Paul. Please find the reponse of the system on the screenshot.Number of Rows.jpg

 

Nevertheless, the column Number of Rows exists...

Please find sample of my pbix file here: Please find my sample pbix file here: https://drive.google.com/file/d/1AWknO_abSZnNmKnzsOdKhhUdF9XbLkfb/view?usp=sharing

 

Thank you in advance for your help!

@Delphia 

[Number of rows] is a measure:

Number of rows =SUM(cleaned_row_count[Number of Rows])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you, Paul. It works as a measure, nevertheless, it shows todays values, not for the previous date. Please have a look at my screenshot:

prev_day.jpg

 

Thank you one more time!

Hi @Delphia,

Can you please share a sample pbix file with some dummy data(keep the raw tale schema) and the expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Notice: please not add sensitive/real data in it.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you for your advice. I've added the link to my question. 

Please find my sample pbix file here: https://drive.google.com/file/d/1AWknO_abSZnNmKnzsOdKhhUdF9XbLkfb/view?usp=sharing

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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