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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Sum using slicer

Hello Power Bi community,

i have data in below format:

YearMonthSales Profit
202312411
202325633
202327622
202317866
202329833
202227644
202219055
202237878
202246765
202259834
202258012

 

Output:

                                               

Analyst_Mehul_0-1705637588675.png

When i select 2022 in slicer i want output like: 2022 Sales:489 

                                                                            2023 Sales: 332

 

Similary when i select 2023  in slicer i want output like: 2022 Sales: 166

                                                                                         2023 Sales : 332

 

reason for above output because 2023 have data till Feb'23 only, so i want to show sum of sales till Feb'22 for 2022 .

 

 

Right now when i select the 2023 slicer it shows sum of sales for 2023 and whole year sales sum for 2022 instead of sum of sales for the months data we have in 2023.

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

@Anonymous 

I modified the year to accommodate 2024:

Sales Compared Year = 

VAR __CurrentYear = SELECTEDVALUE( Table22[Year])
VAR __Year = 
    SWITCH(
        __CurrentYear,
        2022 , 2023, 
        2023, 2022,
        2024 , 2023
    ) 
VAR __Months = VALUES( Table22[Month] )
VAR __Result = 
    CALCULATE(
        [Selected Year Sales],
        Table22[Year] = __Year,
        __Months
    )
RETURN
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
Fowmy
Super User
Super User

@Anonymous 

Create two measure as follows:

Selected Year Sales = SUM(Table22[Sales ])

 

Sales Compared Year = 

VAR __CurrentYear = SELECTEDVALUE( Table22[Year])
VAR __Year = IF( __CurrentYear = 2022 , 2023, 2022) 
VAR __Months = VALUES( Table22[Month] )
VAR __Result = 
    CALCULATE(
        [Selected Year Sales],
        Table22[Year] = __Year,
        __Months
    )
RETURN
    __Result


Expected Results:

When i select 2022 in slicer i want output like: 2022 Sales:489,  2023 Sales: 332

Fowmy_0-1705647817722.png

 

Similary when i select 2023  in slicer i want output like: 2022 Sales: 166, 2023 Sales : 332

Fowmy_1-1705647853748.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hi @Fowmy ,

Thanks for the solution it is working fine for 2 years of data.
what would be the required to make this sol work for 3 years of data like 2022,2023 and 2024.

 

@Anonymous 

In that case, how you would you decide which is the current year and which is the compared year. Say, in the lislicer, you pick 2023 and which year will be considered for comparison, 2022 or 2024? what is the logic?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hi @Fowmy ,

Thanks for the response.

 

With 3 years of data(2022,2023,2024), 

 

When  we select 2022 in the slicer : 2022 will be the current year and 2023 will be compared year.

 

When  we select 2023 in the slicer: 2023 will be current year and 2022 will be compared year(As we don't have full year of 2024 data so we will be comparing it with 2022 only.).

 

When we select 2024 in slicer: 2024 will be current year and 2023 will be compared year.

 

Thanks in advance.

@Anonymous 

I modified the year to accommodate 2024:

Sales Compared Year = 

VAR __CurrentYear = SELECTEDVALUE( Table22[Year])
VAR __Year = 
    SWITCH(
        __CurrentYear,
        2022 , 2023, 
        2023, 2022,
        2024 , 2023
    ) 
VAR __Months = VALUES( Table22[Month] )
VAR __Result = 
    CALCULATE(
        [Selected Year Sales],
        Table22[Year] = __Year,
        __Months
    )
RETURN
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I am getting belwo error while using above created measure in the calculation:

Rare_analyst_0-1710998412500.png

what should i do?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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