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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

CONDITIONAL DATES

Hi,

 

I'm developing a daily report in Power BI, but if the user select a date where there´s no data, Power BI should select data from the last date with information:

 

CASE 1 - The user selected a date with data: Power BI should list the information for the selected date.

CASE 2 - The user selected a date with no data: Power BI should show information from the last date for each Facility:

 

Facilities    Date              Values

---------------------------------

FAC001     2021-08-16   3,000

FAC002     2020-10-01   2,500

FAC003     2019-11-03   4,000

 

Is there a way to do this?

 

Thank you,

 

Benedito Almeida.

1 ACCEPTED SOLUTION

Try:

Sum Values =
VAR MaxDate = MAXX(FILTER(ALL(Table[Date), Table[Date] <= SELECTEDVALUE(IndDate[Date]) && NOT(ISBLANK(SUM(Table[Values])))), Table[Date])

RETURN

CALCULATE(SUM(Table[Values]), FILTER(ALL(Table[Date]), Table[Date] = MaxDate)




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.






View solution in original post

8 REPLIES 8
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

I simulated some optional dates, hoping to achieve your expected results.

  1. Create a new column in the Date table.

 

New date = 
IF (
    [Selectable date]
        = CALCULATE (
            MAX ( 'Table'[Date ] ),
            FILTER ( 'Table', [Date ] = EARLIER ( 'Date'[Selectable date] ) )
        ),
    [Selectable date],
    CALCULATE (
        MAX ( 'Table'[Date ] ),
        FILTER ( 'Table', [Date ] < EARLIER ( 'Date'[Selectable date] ) )
    )
)
New value = 
CALCULATE (
    MAX ( 'Table'[Values] ),
    FILTER ( 'Table', [Date] = EARLIER ( 'Date'[New date] ) )
)

 

vzhangti_0-1637034399495.png

 

    2. The new Date table needs to establish a relationship with the original table.

vzhangti_1-1637034438085.png

 

  3. Create a new date slicer in the view, and the final result is shown in the figure.

vzhangti_2-1637034464280.jpeg

 

If the method I provided above can't solve your problem, what's your expected result? Could you please provide more details for it?

 

Best Regards,

Community Support Team _Charlotte

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

 

 

 

Anonymous
Not applicable

Hello, everyone

I would like to thank you all for your help.

I've decided to create a stored procedure to select the data I need for the report.

The SP is working corretly.

My question now is: can I pass the report slicer (it's a date) as a parameter to the stored procedure?

This would solve my problem completely.

Thank you all.

Benedito_1967.

Hi, @Anonymous 

 

Create a new calendar table.

 

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

 

 

New measure takes the date selected in the slicer.

 

New Date = MAX('Date'[Date])
Output date = 
IF (
    [New Date] = MAX ( 'Table'[Date] ),
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALL ( 'Table' ), [Date] = MAX ( 'Table'[Date] ) )
    ),
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALL ( 'Table' ), [Date] < MAX ( 'Date'[Date] ) )
    )
)
New Facilities =
CALCULATE (
    MAX ( 'Table'[Facilities] ),
    FILTER ( ALL ( 'Table' ), [Output date] = MAX ( 'Table'[Date] ) )
)
New value = 
CALCULATE (
    MAX ( 'Table'[Values] ),
    FILTER ( ALL('Table'), [Date] =MAX('Table'[Date] ) )
)

 

vzhangti_0-1637650637877.png

 

Is this the case when the date slicer you mentioned is selected as a parameter? If you have any other questions, please reply.

 

Best Regards,

Community Support Team _Charlotte

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

Anonymous
Not applicable

Hello,

I would like to thank you all for your help.

You really saved me hours of work.

Benedito_1967.

PaulDBrown
Community Champion
Community Champion

You will need an independent date table for the slicer. Let's call this table IndDate

Sum Values =
VAR MaxDate = MAXX(FILTER(ALL(Table), Table [Date] <= SELECTEDVALUE(IndDate[Date]) && NOT(ISBLANK(SUM(Table[Values])))), Table[Date])

RETURN

CALCULATE(SUM(Table[Values]), FILTER(ALL(Table), Table[Date] = MaxDate)





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.






Anonymous
Not applicable

Good morning, Paul

Thank you very much for your input.

I tried to use your sugestion, but the report now returns the same value for all FACILITIES, like this:

Facilities    Date              Values

---------------------------------

FAC001     2021-08-16   90.24

FAC002     2021-08-16   90.24

FAC003     2021-08-16   90.24

What I really need is that for each FACILITY the report returns its last date and value.

Benedito Almeida.

Try:

Sum Values =
VAR MaxDate = MAXX(FILTER(ALL(Table[Date), Table[Date] <= SELECTEDVALUE(IndDate[Date]) && NOT(ISBLANK(SUM(Table[Values])))), Table[Date])

RETURN

CALCULATE(SUM(Table[Values]), FILTER(ALL(Table[Date]), Table[Date] = MaxDate)




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.






Greg_Deckler
Community Champion
Community Champion

@Anonymous Maybe something like:

Measure =
  VAR __Date = SELECTEDVALUE('Calendar'[Date])
  VAR __Value = CALCULATE(SUM('Table'[Values]),[Date]=__Date)
  VAR __NewDate = IF(ISBLANK(__Value),MAX('Table'[Date]),__Date)
RETURN
  CALCULATE(SUM('Table'[Values]),[Date]=__NewDate)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.