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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jitmondo
Helper III
Helper III

Target % not correct when using a filter to a category

Hi All,

 

this is probably very simple but have not found it online or atleast the searches I have are not right.

 

I have a sales target of lets say 100 and and within that 100 are categories - example cars 50 and bikes 50

 

I get a percentage out of 100 which is fine but when I filter down to categories the dax below will still use 100 as the denominator. I want to be able to filter to cars or bikes and the sales amount to be calculated against the target number for that category

 

any idea on what I can put in to enable me to filter to different categories

 

Target % = calculate('salestable'[salessum]/'targettable'[targetsum])
 
any advice would be awesome thanks
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Jitmondo , try like

 

Target % = calculate(Divide('salestable'[salessum], calculate('targettable'[targetsum], allselected() ) ) )

 

or

 

Target % = calculate(Divide('salestable'[salessum], calculate('targettable'[targetsum], all() ) ) )

View solution in original post

v-xiaotang
Community Support
Community Support

Hi @Jitmondo 

You can try this, create the measure below

Target % =
VAR _category =
    SELECTEDVALUE ( Slicer[categories] )
VAR _salessum =
    CALCULATE (
        SUM ( salestable[sales] ),
        FILTER ( ALL ( salestable ), salestable[categories] = _category )
    )
VAR _targetsum =
    CALCULATE (
        SUM ( targettable[target] ),
        FILTER ( ALL ( targettable ), targettable[categories] = _category )
    )
RETURN
    IF (
        ISBLANK ( _category ),
        'salestable'[salessum] / 'targettable'[targetsum],
        _salessum / _targetsum
    )

result

vxiaotang_2-1652756947209.pngvxiaotang_1-1652756937590.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Jitmondo 

You can try this, create the measure below

Target % =
VAR _category =
    SELECTEDVALUE ( Slicer[categories] )
VAR _salessum =
    CALCULATE (
        SUM ( salestable[sales] ),
        FILTER ( ALL ( salestable ), salestable[categories] = _category )
    )
VAR _targetsum =
    CALCULATE (
        SUM ( targettable[target] ),
        FILTER ( ALL ( targettable ), targettable[categories] = _category )
    )
RETURN
    IF (
        ISBLANK ( _category ),
        'salestable'[salessum] / 'targettable'[targetsum],
        _salessum / _targetsum
    )

result

vxiaotang_2-1652756947209.pngvxiaotang_1-1652756937590.png

 

Best Regards,

Community Support Team _Tang

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

amitchandak
Super User
Super User

@Jitmondo , try like

 

Target % = calculate(Divide('salestable'[salessum], calculate('targettable'[targetsum], allselected() ) ) )

 

or

 

Target % = calculate(Divide('salestable'[salessum], calculate('targettable'[targetsum], all() ) ) )

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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