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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
powerbeye
New Member

check if anything selected in Slicer, then do sum based on selected Slicer values

Hi,

 

I'm new to DAX and cannot find a solution to this problem I'm having.

I've come up with a Measure formula that is only partially working unfortuntely. 

 

I have a data table in my report:

Manager Activity CostCategory Year Month AnnualBudget 
JohnDoeIT80020231$250
JohnDoeIT90020231$50
JohnDoeIT80020232$250
JohnDoeIT90020232$50


I have four slicers that users select from:
Manager, Activity, Year, Month

I have measure that calculates Total of Annual budget based on those slicer selections and shows the Sum value on Card. 
For example, if I have Slicers selected like below:
Manager=JohnDoe, Activity=IT, Year=2023, Month=1, then my measure value would be $300 on the Card which is correct.

The problem I'm having is when a Month is NOT selected the Card shows $600 - the sum of all Months.
Since budget amount is set in the begining of year and doesnt change over month till end of year, I want it to sum only for single month, not all 12 months. 

What I would like:
- if nothing selected on Slicer, show message "Please select from criteria first" on the Card
- if only Slicer Manager, Activity are selected, show message "Please select a year also" on the Card
- if Slicer Manager, Activity, Year are selected, show $300 on the Card (the sum value of single month only)
- if all selected, show $300 on the Card

My measure code is only working correctly when Month is also selected, otherwise it's multiplying that amount which I dont want. 

 

 

FinalAnnualBudget = 
var ManagerSelected = SELECTEDVALUE(Expense[Manager], "")
var ActivitySelected = SELECTEDVALUE(Expense[Activity], "")
var YearSelected = SELECTEDVALUE(Expense[FISCAL_YEAR], "")
var val = IF(AND(NOT ISBLANK(ActivitySelected), NOT ISBLANK(YearSelected)), 
"$" & CONVERT(SUM(Expense[Annual_Budget]), STRING), "Please select from criteria first")
return val

 

 

Another issue I'm having is when I show the message "Please select from criteria first", it's not fitting inside the Card because the Card is formatted to show Currency. Is it possible to also format the message by making the text size smaller and change the color in Measure code or in some other way?

Thank you.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @powerbeye ,

 

Here are the steps you can follow:

1. Create measure.

Measure  =
SWITCH(
    TRUE(),
ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&NOT(ISFILTERED('Table'[Year]))&&NOT(ISFILTERED('Table'[Month])) ,"Please select a year also",
ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&ISFILTERED('Table'[Year])&&NOT(ISFILTERED('Table'[Month])),SUMX(FILTER(ALLSELECTED('Table'),'Table'[Month]=MAX('Table'[Month])),[AnnualBudget]),  ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&ISFILTERED('Table'[Year])&&ISFILTERED('Table'[Month]),SUMX(ALLSELECTED('Table'),[AnnualBudget]),
    "Please select from criteria first"
   )

2. Result:

vyangliumsft_0-1698040131186.png

 

vyangliumsft_1-1698040131188.png

vyangliumsft_2-1698040180658.png

 

vyangliumsft_3-1698040180659.png

 

 

Best Regards,

Liu Yang

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

select = SWITCH(
    true(),
    ISFILTERED(buget[Manager])&&ISFILTERED(buget[activity])&&not(ISFILTERED(buget[year]))&&not(ISFILTERED(buget[Month]))," Please select year also ",
    ISFILTERED(buget[Manager])&&ISFILTERED(buget[activity])&&ISFILTERED(buget[year])&&NOT(ISFILTERED(buget[Month])),SUMX(FILTER(ALLSELECTED(buget),buget[Month]=MAX(buget[Month])),buget[annual buget ]),
    ISFILTERED(buget[Manager])&&ISFILTERED(buget[activity])&&ISFILTERED('buget'[year])&&ISFILTERED(buget[Month]),SUMX(ALLSELECTED(buget),[annual buget ]),
    "Please select from criteria first")
 
Anuja_Chaudhari_0-1706611447338.pngAnuja_Chaudhari_1-1706611523551.png

 

 
v-yangliu-msft
Community Support
Community Support

Hi  @powerbeye ,

 

Here are the steps you can follow:

1. Create measure.

Measure  =
SWITCH(
    TRUE(),
ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&NOT(ISFILTERED('Table'[Year]))&&NOT(ISFILTERED('Table'[Month])) ,"Please select a year also",
ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&ISFILTERED('Table'[Year])&&NOT(ISFILTERED('Table'[Month])),SUMX(FILTER(ALLSELECTED('Table'),'Table'[Month]=MAX('Table'[Month])),[AnnualBudget]),  ISFILTERED('Table'[Manager])&&ISFILTERED('Table'[Activity])&&ISFILTERED('Table'[Year])&&ISFILTERED('Table'[Month]),SUMX(ALLSELECTED('Table'),[AnnualBudget]),
    "Please select from criteria first"
   )

2. Result:

vyangliumsft_0-1698040131186.png

 

vyangliumsft_1-1698040131188.png

vyangliumsft_2-1698040180658.png

 

vyangliumsft_3-1698040180659.png

 

 

Best Regards,

Liu Yang

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

ThxAlot
Super User
Super User

Try incoporating ISFILTERED() function into those criteria of your measure.



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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