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
sgk123
Frequent Visitor

Prev Year monthly calculations to set goal for current year month

Hi all,

 

I have a problem in calculating the below scenario by using measures.

Could you please help me with it.

 

I have a table with Product, Location, Year, Quarter, Month, Week (Year Week), Sales

 

ProductLocationYearQuarterMonthWeekSalesGoal
P1L1201611112-
P1L220161122-
P2L120161135-
P3L120161141-
P1L320161155-
P4L220161165-
P4L420161268-
P2L2201612715-
P1L1201711185.71428
P1L2201711247.14285
P2L1201711367.14285
P3L1201711497.14285
P1L3201711572.85714
P4L2201712554.28571
P4L4201712625.225
P2L2201712785.225

 

Goal = ((Sum of sales of previous year same month)/(No of Working days in present year month))* (No of working days in present year that week)

 

How do I calculate goal using measures in Power BI?

6 REPLIES 6

Hi @sgk123

 

First of all, you need to have a proper 'WorkingDay' Column in your Calendar Table. This column must have 2 values: 1 for a working day and 0 for a non-working day.

 

Here is my suggestion (based on 4 DAX Measures):

 

1. Total Sales = Sum (YourTable[SalesAmount])

2. Total Sales LY SameMonth = VAR CurrY = MAX('Calendar'[Year]) VAR CurrMonth = MAX('Calendar'[Month]) Return
CALCULATE( [Total Sales] , FILTER(ALL('Calendar');'Calendar'[Year] = CurrY-1) , FILTER(ALL('Calendar') ,'Calendar'[Month] = CurrMonth ) )

3. Total Working Days = Sum(Calendar[WorkingDay])

4. WorkingDaysThisYthisMonth = Calculate ( Sum(Calendar[WorkingDay]) , All(Calendar[Week]) )

5. Goal = Total Sales LY SameMonth / WorkingDaysThisYthisMonth * Total Working Days

 

As you can see, I broke the measures into several pieces. It makes it clearer to follow the logic of the different steps.

 

Hope it helps you and solves your issue!

 

 

 

Hi @Datatouille,

 

I have a working day in my calendar table.

In the step 2 of your solution

Total Sales LY SameMonth = VAR CurrY = MAX('Calendar'[Year]) VAR CurrMonth = MAX('Calendar'[Month]) Return
CALCULATE( [Total Sales] , FILTER(ALL('Calendar');'Calendar'[Year] = CurrY-1) , FILTER(ALL('Calendar') ,'Calendar'[Month] = CurrMonth ) )

 

Here this is calculating only for Current Month right? For example, it is caluclating only for March.

I need it for all the months

 

Please correct me if I was assuming wrong.

@sgk123: You are right, [Total Sales LY SameMonth] is computing the sales of Last year only for the month in the current filter context.

Isn't what you need? You said: "Sum of sales of previous year same month" in your requirements.

Hi @Datatouille

 

Yeah, but my final requirement is to have that goal as a column added to the table.

I tried doing it, but was unable to.

Could you please help me with it

Hi @sgk123,

 

In your scenairo, you can create below measures:

 

WDThisYM = CALCULATE(SUM('Calendar'[WorkingDay]),FILTER(ALL('Calendar'),Max('Table1'[Year])='Calendar'[Year] && Max('Table1'[Month])='Calendar'[Month]))

 

LYSales = CALCULATE(SUM('Table1'[Sales]),FILTER(ALL('Table1'),'Table1'[Year]=MAX('Table1'[Year])-1 && 'Table1'[Month]=MAX('Table1'[Month])))

 

WDThisYW = CALCULATE(SUM('Calendar'[WorkingDay]),FILTER(ALL('Calendar'),Max('Table1'[Year])='Calendar'[Year] && Max('Table1'[Month])='Calendar'[Month] && MAX('Table1'[Week])='Calendar'[Week]) )

 

Goal = 'Table1'[LYSales]/'Table1'[WDThisYM]*'Table1'[WDThisYW]

 

 

q4.PNG

 

Best Regards,
Qiuyun Yu

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

Hi @v-qiuyu-msft

 

This seems to be fine, but I'm not able to roll up on Product or location level.

The Goals work fine only if week is displayed in any of the graphs/tables

 

i.e., Total of Goals should be equal to 44.96 instead of 5.75

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.