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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Naveen29
Helper II
Helper II

KPI Card data

I would like to show data in the KPI card as below. when user selects current year as 2024 from slicer, it should show sum of sales for groups A,B,C channels and same as for previous year (2023) as well. But when user selects as 2023 from slicer , it should show only group of A,B .How do we achive this?

Naveen29_0-1717431141788.png

 

 

 

 

3 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @Naveen29 Create a two measure for current year sales and previous year sales as below

 

SalesCurrentYear =
VAR SelectedYear = SELECTEDVALUE('Date'[Year])
RETURN
IF(
SelectedYear = 2024,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B", "C"},
YEAR('Sales Data'[Date]) = 2024
),
IF(
SelectedYear = 2023,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B"},
YEAR('Sales Data'[Date]) = 2023
),
BLANK()
)
)

 

Create another measure for Previous Year

SalesPreviousYear =
VAR SelectedYear = SELECTEDVALUE('Date'[Year])
RETURN
IF(
SelectedYear = 2024,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B", "C"},
YEAR('Sales Data'[Date]) = 2023
),
IF(
SelectedYear = 2023,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B"},
YEAR('Sales Data'[Date]) = 2022
),
BLANK()
)
)

 

Create a KPI card visualization for current year and previous year

Set the Indicator to SalesCurrentYear the  measure.Set the Target if needed, or empty. do the same for another KPI card visual for SalesPreviousYear measure.

set the slicer to filter on the year column from date table.

 

Hope it works 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

Ritaf1983
Super User
Super User

Hi @Naveen29 
You can create 2 measures like :

Current total sales = if(max('Calendar'[Year])= 2024,
 CALCULATE([total_sales],'orders'[group] IN {"A","B","C"}),
IF(MAX('Calendar'[Year])=2023 ,CALCULATE([total_sales],'orders'[group] IN {"A","B"})))
 
previ year = if(max('Calendar'[Year])= 2024,
 CALCULATE([total_sales],SAMEPERIODLASTYEAR('Calendar'[Date]),'orders'[group] IN {"A","B","C"}),
IF(MAX('Calendar'[Year])=2023 ,CALCULATE([total_sales],SAMEPERIODLASTYEAR('Calendar'[Date]),'orders'[group] IN {"A","B"})))
Result:
Ritaf1983_0-1717468235046.pngRitaf1983_1-1717468298224.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Anonymous
Not applicable

Thanks for the reply from @rajendraongole1 and@Ritaf1983, please allow me to provide another insight:
Hi,@Naveen29 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1717488254787.png

2.I created the following calculation column as a slicer:

YEARSSS = SELECTCOLUMNS('MAIN',"1",'MAIN'[YEAR])

3. Below are the measure I've created for your needs:

CURRENT = 
VAR SELECTYEAR=SELECTEDVALUE(YEARSSS[YEAR])
VAR PREYEAR=SELECTYEAR-1
RETURN 
IF(ISFILTERED(YEARSSS[YEAR]),SWITCH(TRUE(),
SELECTYEAR=2024,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {PREYEAR}&&'MAIN'[channel] IN {"A","B","C"})),
SELECTYEAR=2023,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {PREYEAR}&&'MAIN'[channel] IN {"A","B"})),FALSE())
,SUM(MAIN[SALES]))
LAST = 
VAR SELECTYEAR=SELECTEDVALUE(YEARSSS[YEAR])
RETURN 
IF(ISFILTERED(YEARSSS[YEAR]),SWITCH(TRUE(),
SELECTYEAR=2024,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {SELECTYEAR}&&'MAIN'[channel] IN {"A","B","C"})),
SELECTYEAR=2023,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {SELECTYEAR}&&'MAIN'[channel] IN {"A","B"})),FALSE())
,SUM(MAIN[SALES]))

4.Here's my final result, which I hope meets your requirements.

 

vlinyulumsft_1-1717488347904.png

vlinyulumsft_2-1717488357779.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.

Best Regards,

Leroy Lu

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

3 REPLIES 3
Anonymous
Not applicable

Thanks for the reply from @rajendraongole1 and@Ritaf1983, please allow me to provide another insight:
Hi,@Naveen29 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1717488254787.png

2.I created the following calculation column as a slicer:

YEARSSS = SELECTCOLUMNS('MAIN',"1",'MAIN'[YEAR])

3. Below are the measure I've created for your needs:

CURRENT = 
VAR SELECTYEAR=SELECTEDVALUE(YEARSSS[YEAR])
VAR PREYEAR=SELECTYEAR-1
RETURN 
IF(ISFILTERED(YEARSSS[YEAR]),SWITCH(TRUE(),
SELECTYEAR=2024,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {PREYEAR}&&'MAIN'[channel] IN {"A","B","C"})),
SELECTYEAR=2023,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {PREYEAR}&&'MAIN'[channel] IN {"A","B"})),FALSE())
,SUM(MAIN[SALES]))
LAST = 
VAR SELECTYEAR=SELECTEDVALUE(YEARSSS[YEAR])
RETURN 
IF(ISFILTERED(YEARSSS[YEAR]),SWITCH(TRUE(),
SELECTYEAR=2024,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {SELECTYEAR}&&'MAIN'[channel] IN {"A","B","C"})),
SELECTYEAR=2023,CALCULATE(SUM(MAIN[SALES]),FILTER(ALL('MAIN'),'MAIN'[YEAR] IN {SELECTYEAR}&&'MAIN'[channel] IN {"A","B"})),FALSE())
,SUM(MAIN[SALES]))

4.Here's my final result, which I hope meets your requirements.

 

vlinyulumsft_1-1717488347904.png

vlinyulumsft_2-1717488357779.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Ritaf1983
Super User
Super User

Hi @Naveen29 
You can create 2 measures like :

Current total sales = if(max('Calendar'[Year])= 2024,
 CALCULATE([total_sales],'orders'[group] IN {"A","B","C"}),
IF(MAX('Calendar'[Year])=2023 ,CALCULATE([total_sales],'orders'[group] IN {"A","B"})))
 
previ year = if(max('Calendar'[Year])= 2024,
 CALCULATE([total_sales],SAMEPERIODLASTYEAR('Calendar'[Date]),'orders'[group] IN {"A","B","C"}),
IF(MAX('Calendar'[Year])=2023 ,CALCULATE([total_sales],SAMEPERIODLASTYEAR('Calendar'[Date]),'orders'[group] IN {"A","B"})))
Result:
Ritaf1983_0-1717468235046.pngRitaf1983_1-1717468298224.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
rajendraongole1
Super User
Super User

Hi @Naveen29 Create a two measure for current year sales and previous year sales as below

 

SalesCurrentYear =
VAR SelectedYear = SELECTEDVALUE('Date'[Year])
RETURN
IF(
SelectedYear = 2024,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B", "C"},
YEAR('Sales Data'[Date]) = 2024
),
IF(
SelectedYear = 2023,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B"},
YEAR('Sales Data'[Date]) = 2023
),
BLANK()
)
)

 

Create another measure for Previous Year

SalesPreviousYear =
VAR SelectedYear = SELECTEDVALUE('Date'[Year])
RETURN
IF(
SelectedYear = 2024,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B", "C"},
YEAR('Sales Data'[Date]) = 2023
),
IF(
SelectedYear = 2023,
CALCULATE(
SUM('Sales Data'[SalesAmount]),
'Sales Data'[Channel] IN {"A", "B"},
YEAR('Sales Data'[Date]) = 2022
),
BLANK()
)
)

 

Create a KPI card visualization for current year and previous year

Set the Indicator to SalesCurrentYear the  measure.Set the Target if needed, or empty. do the same for another KPI card visual for SalesPreviousYear measure.

set the slicer to filter on the year column from date table.

 

Hope it works 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.