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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Petter120
Helper I
Helper I

Get Last 6 month from slicer date

Hi i have this formula 

 

Ton1 = CALCULATE(SUM(Lastdata_T[Ton]);DATESBETWEEN(Datum_T[Datum];MAX(Datum_T[Datum])-7;MAX(Datum_T[Datum])))

that returns the end date in a slicer and the  7 previous date in the chart below

 

 Does anynone know how to modify this formula so it doesnt return 7 previous days but the 6 previous months instead ??

 

 

Best regards 

Petter

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@Petter120,

Please check if the following measure returns your expected result.

Ton1 = var Ldate=MAX(Datum_T[Datum])
var Fdate=EDATE(Ldate;-6)
return CALCULATE(SUM(Lastdata_T[Ton]);DATESBETWEEN(Datum_T[Datum];Fdate;Ldate))



Regards,
Lydia

Community Support Team _ Lydia 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

5 REPLIES 5
v-yuezhe-msft
Employee
Employee

@Petter120,

Please check if the following measure returns your expected result.

Ton1 = var Ldate=MAX(Datum_T[Datum])
var Fdate=EDATE(Ldate;-6)
return CALCULATE(SUM(Lastdata_T[Ton]);DATESBETWEEN(Datum_T[Datum];Fdate;Ldate))



Regards,
Lydia

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

I get this error

 

The following syntax error occurred during parsing: Invalid token, Line 3, Offset 59, [Datum;Fdate;Ldate))))))))))))))))).

// Petter

 

@Petter120,

I have edited my reply, please re-check the dax.

Regards,
Lydia

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

Hi Petter

 

Try this .

 

CALCULATE(SUM(Lastdata_T[Ton]), DATESBETWEEN( Datum_T[Datum],MONTH(DATEADD(MAX(Sheet2[Date]),-6,MONTH)),Month(MAX(Datum_T[Datum]))))

 

P.S: I havent tested this as am not at my laptop now. Just edited your formula.

 

Thanks
Raj

The formula has an error in this section.

Do i have to create another datetable called ("Sheet2[Date]) ?

 

 

(MAX(Sheet2[Date])

It gets red even if i put my ordinary date table there as well

 

CALCULATE(SUM(Lastdata_T[Ton]);DATESBETWEEN( Datum_T[Datum];MONTH(DATEADD(MAX(Datum_T[Datum]);-6;MONTH));Month(MAX(Datum_T[Datum]))))

 

// Petter

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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