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
Amar-Agnihotri
Resolver I
Resolver I

I Have a date Column in my direct query data, i want to add a dax which will show previous work Data

I Have a date Column in my direct query data, i want to add a dax which will show previous working day data that means if today is monday it should show friday's data and if today is tuesday it should monday's data, also if it is sunday it should show friday's data only. I can't add column measure as direct query doesn't allow that. How to do this ?

 

Thanx in advance

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

Hi  @Amar-Agnihotri ,

 

Create 2 columns as below:

Is working day = IF(WEEKDAY('Table'[Date],2)=6||WEEKDAY('Table'[Date],2)=7,0,1)
previous work Data = 
var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Is working day]=1))
Return
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Date]=_maxdate))

And you will see:

vkellymsft_0-1628669231056.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Hi  @Amar-Agnihotri ,

 

Create 2 columns as below:

Is working day = IF(WEEKDAY('Table'[Date],2)=6||WEEKDAY('Table'[Date],2)=7,0,1)
previous work Data = 
var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Is working day]=1))
Return
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Date]=_maxdate))

And you will see:

vkellymsft_0-1628669231056.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

v-kelly-msft
Community Support
Community Support

Hi  @Amar-Agnihotri ,

 

Create 2 columns as below:

Is working day = IF(WEEKDAY('Table'[Date],2)=6||WEEKDAY('Table'[Date],2)=7,0,1)
previous work Data = 
var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Is working day]=1))
Return
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Date]=_maxdate))

And you will see:

vkellymsft_0-1628669231056.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

huey999
New Member

Hi, You need to another column to your date table - PreviousWorkingDay and populate it with the DateDimID (YYYYMMDD integer) of the PreviousWorkingDay. 

 

Then, create a calculation as below

 

PremiumAmount_PriorWorkday_total:= CALCULATE ([Totalbyworkingday],

FILTER (

ALL ('Date'),

'Date'[DateDimID]=max('Date'[PreviousWorkDay])

)

 

there's an article on SQLBI for the same sort of calculations. You may need to search a bit to find it as I cant remember the name.  

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.