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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
DataFab2023
Frequent Visitor

Calculation based on two dates

Hi guys,

 

I have to calculate the sales on the scenario below:

 

I have a dim_date filter that has no relationship with the sales table and I need to use that as slicer.

 

Each sale has its own period start based on the [Start] column and let's say I select 28/03/2023 I want to see everything from 01/01/2023 until 28/03/2023 (because the period start is 01/01/2023 for that row and 28/03/2023 is the date I selected from the sliecer)

Now If I select 04/04/2023 in the slicer and the period start for that row is 01/04/2023 so I want to see everything from 01/04/2023 to 04/04/2023

 

What determines that start period is the [Start] column

 

How can I achieve that?

 

DataFab2023_0-1684306990243.png

 

 

here is the link for the file

test.zip

 

 

Thanks a lot

1 ACCEPTED SOLUTION

Hi , @DataFab2023 

Thanks for your quick response!I may have a mistake in my dax code , you can try to use this dax:

Measure = var _slicer =MAX('Dim_Date2'[Date Filter])
var _start = MINX( FILTER(ALLSELECTED('Sheet1'),'Sheet1'[Date]=_slicer) , [Start])
var _date = MAX('Sheet1'[Date])
return
IF(_date>=_start && _date<= _slicer,1,0)

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

4 REPLIES 4
bhelou
Responsive Resident
Responsive Resident

Dear , 

Make the relationship from DIM_DATE to the Sheet1 Dates : 1 to many 

Then in the sclicer make it as hierarchy and select only year and quarter : 

Attached images 


bhelou_0-1684651161054.png

bhelou_3-1684651236489.png

 


Kindly accept as a solution and a kudo would be greatfull . 
Regards , 

 

v-yueyunzh-msft
Community Support
Community Support

Hi , @DataFab2023 

Thanks for you sample .pbix file firsr~

Here are the steps you can refer to :
We can click "New Measure" to create a measure like this:

Measure = var _slicer =MAX('Dim_Date2'[Date Filter])
var _start = MINX( FILTER('Sheet1','Sheet1'[Date]=_slicer) , [Start])
var _date = MAX('Sheet1'[Date])
return
IF(_date>=_start && _date<= _slicer,1,0)

 

Then we can put this measure on the "Filter on this visual"  for this visual:

vyueyunzhmsft_0-1684469418291.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Hi there,

 

thanks for taking the time for this one.


The measure almost worked, the problem is that when I select 15/04/2023 for example the start period (from the start column) is 01/04/2023 there it should show data only from 01/04/2023 and not 15/01/2023

 

DataFab2023_0-1684647622091.png

 

Hi , @DataFab2023 

Thanks for your quick response!I may have a mistake in my dax code , you can try to use this dax:

Measure = var _slicer =MAX('Dim_Date2'[Date Filter])
var _start = MINX( FILTER(ALLSELECTED('Sheet1'),'Sheet1'[Date]=_slicer) , [Start])
var _date = MAX('Sheet1'[Date])
return
IF(_date>=_start && _date<= _slicer,1,0)

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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