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
Ncio
Helper II
Helper II

Add a dax formula to a slicer?

Hello, 

 

I have a graph with a slicer that works well. I'd like to add one choice to the slicer but it's a "dax formula" and I'm not sure how to do it.

 

The slicer allows to select a type of training session (online, face to face, ...) and the graph displays the number of session over the year (year to date, current and past year)

 

Training sessions:

  • Online
  • Face to face
  • Cancelled
  • Active sessions (dax formula: basically "sum(all sessions) - sum(cancelled)" )

 

I understand that one solution would be to to calculate everything in a new calculated table using SUMMARIZE.

  • Is it the most simple solution ? A best practice?

 

 

Note: I have no issue with the Dax, the question is really about adding the choice in the slicer.

 

Thank you,

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Ncio , Not very clear. Are you looking for measure slicer

 

https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slic...
https://www.youtube.com/watch?v=vlnx7QUVYME

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

Hi @Ncio 

I would suggest you:

1. Create an additional table to act as the slicer, which includes the existing Training Session values plus the special value of "Active sessions". Here is how you could create the table using DAX:

Training Sessions = 
UNION ( 
    ALLNOBLANKROW ( ExistingTable[Training Session] ),
    { "Active sessions" }
)

2. Create a relationship between this new table and the existing table with the Training Session column.

3. Use the Training Session column of the new table on the slicer.

4. Write a new measure that handles the "Active sessions" option. Something like:

Number of Sessions =
IF ( 
    SELECTEDVALUE ( 'Training Sessions'[Training Session] ) = "Active sessions",
    <Special expression for Active sessions>, -- May need REMOVEFILTERS ( 'Training Sessions'[Training Session] )
    <Existing session count measure>
)

 Note that the special expression for Active sessions would likely need to remove the filter on 'Training Sessions'[Training Session] because the value "Active sessions" does not match any rows of your original table.

 

This article on Top & Other products covers something similar as far as model setup.

 

Reards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
amitchandak
Super User
Super User

@Ncio , Not very clear. Are you looking for measure slicer

 

https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slic...
https://www.youtube.com/watch?v=vlnx7QUVYME

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hello,

 

Yes, I will switch to a measure slicer to cover all the requirements including the "calculation"

 

Thank you,

selimovd
Super User
Super User

Hello @Ncio ,

 

you cannot add a measure to a slicer.

A measure always needs a context to give a result, like sum by location or by product category. So it wouldn't work in a slicer.

 

You can add values as a calculated column and use that as a slicer. Would that work for your case?

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi

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!

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.