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
kumaayu
Regular Visitor

Calculate measure dynamically based on multiple Filter selection

Hello everyone,

I have been breaking my head on this for the last 48 hours! and finally I seek help..!

 

Lets say I have the following dataset:

 

RegionCountryCategoryDevicePageviews
WestUSCategory Adesktop999
WestUSCategory Amobile100
WestUSCategory Atablet999
WestUSCategory Bdesktop1499
WestUSCategory Bmobile1355
WestUSCategory Btablet678
WestUSCategory Cdesktop1200
WestUSCategory Cmobile708
WestUSCategory Ctablet167
EuropeGBCategory Adesktop1500
EuropeGBCategory Amobile320
EuropeGBCategory Atablet195
EuropeGBCategory Bdesktop536
EuropeGBCategory Bmobile16
EuropeGBCategory Btablet25
EuropeGBCategory Cdesktop1600
EuropeGBCategory Cmobile357
EuropeGBCategory Ctablet990

 

On my report I have 2 visual filters: 1 for Category and another for say country.

I need to display the value for whats the desktop share, mobile share and tablet share (and the measures should adjust dynamically based on the filter selection!)

 

What I did so far:

Created measure for desktop share:

 

Desktop Share =
VAR Selection = IF (
    ISFILTERED ( 'Table'[Category]),
    FILTERS ('Table'[Category]),""
) RETURN 
 CALCULATE(IF (Selection = "", 
  CALCULATE (
        SUM('Table'[Pageviews]),
        ALL ('Table'),
        FILTER ('Table', TRIM('Table'[Device]) = "desktop")
    ) /
 CALCULATE (
        SUM('Table'[Pageviews]),
        ALL ('Table')
    ),
 
 CALCULATE (
        SUM('Table'[Pageviews]),
        ALL ('Table'),
        FILTER ('Table', TRIM('Table'[Device]) = "desktop" && TRIM('Table'[Category]) = Selection)
    ) /
 CALCULATE (
        SUM('Table'[Pageviews]),
        ALL ('Table'),
  FILTER ('Table', TRIM('Table'[Category]) = Selection)
    ))) 

 

 

This works OK if I would have had just 1 filter. As I want multiple filters I feel confused what would be the way to do this?

Any help would be really appreciated. Please let me know if you would like me to elaborate more on my question!

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@kumaayu

 

Try this MEASURE

 

Market Share =
DIVIDE (
    SUM ( 'Table'[Pageviews] ),
    CALCULATE ( SUM ( 'Table'[Pageviews] ), ALLSELECTED ( 'Table' ) )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@kumaayu

 

Try this MEASURE

 

Market Share =
DIVIDE (
    SUM ( 'Table'[Pageviews] ),
    CALCULATE ( SUM ( 'Table'[Pageviews] ), ALLSELECTED ( 'Table' ) )
)

Regards
Zubair

Please try my custom visuals

Thank you very much! I see how, ALLSELECTED helps! 

 

I did the following and it worked like a charm for me.... 

Desktop Share2 =
DIVIDE (
CALCULATE (
SUM('Table'[Pageviews]),
ALL ('Table'),
FILTER ('Table', TRIM('Table'[Device]) = "desktop")
),
CALCULATE (SUM('Table'[Pageviews]), ALLSELECTED ('Table'))
)

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.