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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply

Measure to deduct one day from parameter entered

I'm a bit of a learner and practising my skills to make a rainfall viz.  Just for fun I have created a paramater that returns the number of days it has rained on the user's birthday, but I have hit a snag and would be sooooo grateful for some help!  The rainfall data refers to the rainfall up until 9:00am for the date entered.  So if someone enters their birthdate, I need for the date to adjust to the day before (dateadd-1) to calculate based on the rain for the day prior.  I have used the dateadd function, but because my parameters are to enter day month and year separately, if someone enters a date that is the 1st of a month, i get a snag because there is no -1 date.  I am trying to avoid a whole lot of 'IF' statements that would have to vary depending on the previous month having 31, 30, 29 or 28 days.  I just want it to go back one day based on the total of the date entered? 

Here is my measure:  

Parameter count rainfall from date = CALCULATE(
[Count rainfall Days],
FILTER(Station, Station[Station] = "Craigieburn/Epping"),
FILTER('Dates',
Dates[Day] = 'Select Day'[Select Day Value]-1
&& 'Dates'[Month No] = 'Select Month'[Select Month Value]
&& 'Dates'[Year No]>='Select Year'[Year Value]
))
 
 

Capture.JPG

2 ACCEPTED SOLUTIONS

@tigersandblues , previous day should work. Can you share sample data and sample output in table format?

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

So i ended up fixing it by using a calculated columns in my date table (previous date/day), but i would have rather be able to incorporate the previous day calculation in my dax formula:(

Birthday rain  

 

Parameter count rainfall from previous date = CALCULATE(
[Count rainfall Days],
FILTER(Station, Station[Station] = "Craigieburn/Epping"),
FILTER('Dates',
'Dates'[Previous day number] = 'Select Day'[Select Day Value]
&& 'Dates'[Previous day month number] = 'Select Month'[Select Month Value]
&& 'Dates'[Previous day year number]>='Select Year'[Year Value]
))

 

 

 

 

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@tigersandblues , Create a date from year, month and day .

 

Date = Date([Year],[Month No],[Day])

Now join this date with date of date table .

You can have this kind of formula for today and yesterday

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))
Diff COlumn = datediff(maxx(filter(Table,Table[Date]<earlier(Table[Date]) && Table[Numberf]= earlier(Table[Numberf])  ),Table[Date]) ,Table[Date],Day)

This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))

 

Last 2 day


Rolling 2 day = CALCULATE(sum(Table[Number]),DATESINPERIOD('Date'[Date],MAX(Table[Date]),-2,Day))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

So Amitchandak, when you say Create a date from year, month and day . Date = Date([Year],[Month No],[Day]), do you mean i need to create an additional date table, or is that a calculated column or a measure?  (Sorry if I sound like a goose!)

 

lbendlin
Super User
Super User

instead of separate dropdowns for the day, month and year have you considered using a date slicer or a single date picker control?

I have tried using the date picker, but i can't see an option where it could pick day and month after a certain year.  So for the days it rained on someone's birthday, i would need to include all of the day/month possibilites on or after a certain year?  PS. I am using a separate date table as recommended.  I also previously tried a calculated column in my date table for 'previous day' but couldn't seem to make that work in my measure.

Capture2.JPGCapture3.JPG

 

@tigersandblues , previous day should work. Can you share sample data and sample output in table format?

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Is this what you mean?

Sample output but includes date 

 

Parameter count rainfall from dateDate
114/06/2018 0:00
114/06/2019 0:00
114/06/2020 0:00

Capture4.JPG

Rainfall data sample

YearMonthDayRainfall amount (millimetres)
2018 1120
20181133.4
201811422
20181150
    

Sample workbook 

So i ended up fixing it by using a calculated columns in my date table (previous date/day), but i would have rather be able to incorporate the previous day calculation in my dax formula:(

Birthday rain  

 

Parameter count rainfall from previous date = CALCULATE(
[Count rainfall Days],
FILTER(Station, Station[Station] = "Craigieburn/Epping"),
FILTER('Dates',
'Dates'[Previous day number] = 'Select Day'[Select Day Value]
&& 'Dates'[Previous day month number] = 'Select Month'[Select Month Value]
&& 'Dates'[Previous day year number]>='Select Year'[Year Value]
))

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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