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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anmolgan
Post Prodigy
Post Prodigy

How to write dax formula which should calculate on selection of a date on slicer?

How can write a DAX measure so that I select my date from the slicer and last year from the slicer, and the DAX function should calculate total sales from last year to that date?

8 REPLIES 8
v-lili6-msft
Community Support
Community Support

HI @Anmolgan 

Just try use the logic of this formula:

Result = 
CALCULATE (
    SUM ( 'Monthly Collection Report PBI'[Debit credit value] ),
    DATESBETWEEN (
        Data[Data],
        SAMEPERIODLASTYEAR( Data[Data] ),
        LASTDATE ( Data[Data] )
    )
)

 

Regards,

Lin

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

Now I have 2 dates one is the date where I define my parameter and 2nd date table is where I match this date with all the other dates, so i am confused how can I edit the DAX to actual match the parameter date passed with all the other dates that are in other table?

hi @Anmolgan 

Sample data and expected output would help tremendously.
Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Regards,

Lin

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

Hi @v-lili6-msft  am attaching the one drive link for sample data, please let me know what can be done here, the Data[Data] is my by default parameter, I want to pass in the parameter where Result should caluclate from that period -1 year, that will be my amount.

 

https://ifitech-my.sharepoint.com/:u:/g/personal/anmol_ganju_ifi_tech/ESpM9SH6tThNlTV3nQSgGksB3JG_cI...

hi @Anmolgan 

After my test on your sample pbix file, I found that the column [Base Date.Base Date Level 01] in Monthly Collection Report PBI is not a date column but Data[data] is a date column, so the relationship between them is wrong.

You should adjust it as below:

Step1:

Add a column that format [data] column is 'dd.mm.yyyy'

NEWFORMAT DATA = FORMAT(Data[Data],"dd.mm.yyyy")

2.JPG

Step2:

Then create the relationship between Monthly Collection Report PBI table and data table by this column

3.JPG

 

Step3:

Now adjust the formula as below:

Opening Bal = CALCULATE(SUM('Monthly Collection Report PBI'[Debit credit value]), DATESBETWEEN(Data[Data], SAMEPERIODLASTYEAR(Data[Data]), LASTDATE(Data[Data])))

 

Regards,

Lin

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

@v-lili6-msft  am sorry, but I forgot to tell you that I am using Posting date for matching and not base date, but I think both of my dates are in correct format?

HI @Anmolgan 

If so, this should work well.

and in your report, you have filter the [Base Date.Base Date Level 01] slicer is '04.08.2012' and [Fiscal year.Fiscal year Level 01] is 'V3/2012', the data is '12/30/2016' it will return the data that from '1/1/2015' to '12/30/2016', these three conditions conflict.

6.JPG

 

and if I remove the filter

7.JPG

Opening Bal = CALCULATE(SUM('Monthly Collection Report PBI'[Debit credit value]), DATESBETWEEN(Data[Data], SAMEPERIODLASTYEAR(Data[Data]), LASTDATE(Data[Data])))

 

Regards,

Lin

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

Thanks for the response, I have managed to build this, but the DAX function you have suggested is not validating correctly for the values coming by using the DAX function, Sameperiodlastyear will give me a current date sales right?

 

I want sales happend for this date lets say 31/12/2019 plus last year sales upto the date (31/12/2019)

 

I aplogize if I have not explained this correctly, I think I need to use previous year dax, any examples how can get the above?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors