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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Qamrk
Regular Visitor

Sales by month and calculating variance

Hello,

 

I am using SQL and Excel data to calculate sales by month with multiple filters by using 2 different tables.

 

Sales = CALCULATE(SUM(tblOrderLine[orl_quantity]),
filter(all(tblOrderLine),
tblOrderLine[orl_productId]='Combined forecast'[Prod_Id] &&
RELATED(tblOrder[Year-Month])='Combined forecast'[Year-Month] &&
RELATED(tblOrder[ord_orderStatusName])="invoiced" && RELATED(tblOrder[ord_channelId])<>25
)
)
This shows no error but doesnt not give me the rite output. 
 
After calculating the sales, I am calculating the variance between sales and forecast using the following
 
Variance = IF('Combined forecast'[Date]<TODAY(),IFERROR( ('Combined forecast'[Forecast]-'Combined forecast'[Sales])/('Combined forecast'[Forecast]+'Combined forecast'[Sales]),0),0)
 
And then I need to add the variance of previous 6 months for which I am using the following DAX(does not give the rite output)
 
NFM =
VAR EndDate=
TODAY()-1
Var StartDate=
EDATE(EndDate,-6)
Var Result=
CALCULATE(
    SUM('Combined forecast'[Variance]),
    DATESBETWEEN('Combined forecast'[Date],StartDate,EndDate)
)
Return
Result
 
And then I need to check if an item has Bias or not for which I am using the following that leads to error
 
Bias =
Switch(
    True(),
    'Combined forecast'[NFM]<-1,"Under",
    'Combined forecast'[NFM]>1,"Over",
    "Ok")
 
Qamrk_0-1663351596309.png

Can someone please help me with this? Thank you!

 

-Qamr

 
2 REPLIES 2
Qamrk
Regular Visitor

Hello, 

 

Thank you for the response. I tried to provide sample data. But please let me know if that doesn't make sense or if you have concerns. 

 

Prod_IdDateForecastSalesVarianceMFMBias
20011/12/20202500comes from another table that has Prod_id. This will have multiple filters ; eg: channel id!=25; order_status_name="invoiced"(Forecast-sales)/(Forecast+sales)is um of last 12 calendar months varianceif NFM>2; Over and NFM<-2; under
20012/12/20202200    
20013/12/2020900    
20014/12/2020905    
20015/12/20202300    
20016/12/20202500    
20017/12/2020925    
20031/12/20201200    
20032/12/20201250    
20033/12/20201100    
20034/12/20201110    
20035/12/2020900    
20036/12/2020980    
20037/12/2020900    
20038/12/2020950    
20039/12/20201000    
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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