cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jausting
Frequent Visitor

12 Month Sales

Hi

 

I have created a measure to sum sales over past 12 months, before August 2017

 

I want the measure to calculate the previous 12 month sales from a date that is selected in a slicer (Dates Table0

 

Measure = CALCULATE(sum(EOM_STK[Sales]), 'EOM_STK'[perioddate]<=DATE(2017, 08, 1) && 'EOM_STK'[perioddate]>=DATE(2016, 09, 1))

 

Dates table

 

Year   Month  FilterDate

2017  01         2017-01-01

2017  02         2017-02-01

etc

 

if I substitue the dates for the date slicer, I get the error message that the expression contains multiple columns but only a single column can be used in a true/false expression. What am I doing wrong?

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@jausting,

 

You may add FILTER Function to the formula.

https://www.sqlbi.com/articles/filter-arguments-in-calculate/

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

Hi,

 

Apologies for the delay in responding. Filter was the solution, just wasnt sure how to use it.

 

This was my solution for the sales over 12 months, I had a slicer to select the end period

 

var curDateStr = CALCULATE ( MIN ( Dates2[FilterDate] ), ALLEXCEPT ( Dates2, Dates2[FilterDate] ) )
var curDate = DATE(LEFT(curDateStr,4),VALUE(MID(curDateStr,6,2)),RIGHT(curDateStr,1))
VAR DateAddAlternative = EDATE(curDate,-MonthsToLookBack)
return
CALCULATE ( SUM ( 'EOM_STK'[SOH] ), FILTER(EOM_STK,
                                                    EOM_STK[perioddate]=curDate
))

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.