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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Batman_powerbi
Frequent Visitor

Categorise Plus or Minus %

Hi Team

below is sample data of what i am calculating against

Batman_powerbi_0-1722311206269.png

So far i am able to roll up the calculations whether by function or project and obtain a % difference between estimates/Actuals in $ and same for estimate/actuals in days. i do this with measures 

Difference $ =
VAR __BASELINE_VALUE = SUM('Closed (TABLE)'[Estimate $])
VAR __VALUE_TO_COMPARE = SUM('Closed (TABLE)'[Actual $])
RETURN
    IF(
        NOT ISBLANK(__VALUE_TO_COMPARE),
        DIVIDE(__VALUE_TO_COMPARE - __BASELINE_VALUE, __BASELINE_VALUE)
    )



what i am getting stuck with is categorising the differences across either function or project with a "Plus or minus %" category.
Am trying to mark rows that fall within the plus or minus groups of 10%, 20%, 30% etc 

Batman_powerbi_1-1722311873971.png

Batman_powerbi_3-1722312040566.png

and then be able to count the times each row is counted plus the overall %, similar to output below
Batman_powerbi_2-1722311901538.png

what i want to achieve can be done by summarizing the project and function columns into separate related tables and then create columns from calculations. in essence duplicating the same calculations within the new project or function tables.

am finding this a bit too long winded and hopefully learn how to do this simply in the original table through measures and count rows rather than through multiple tables and columns.

hopefully ive been able to explain this

 

 




1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You can solve this with segmentation.  I have solved a similar problem in the attached file.

Hope this helps.

Ashish_Mathur_0-1722477348076.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

13 REPLIES 13
Ashish_Mathur
Super User
Super User

Hi,

You can solve this with segmentation.  I have solved a similar problem in the attached file.

Hope this helps.

Ashish_Mathur_0-1722477348076.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur thankyou
i was hoping not to go along the lines of creating a custom table which was a path i was heading towards before i started this thread, but if its the only way around it, then happy to accept this as the solution

thankyou

 

 

You are welcome.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

You are welcome.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yaningy-msft
Community Support
Community Support

Hi, @Batman_powerbi 

Thanks for @bhanu_gautam positive reply. You can try following dax to achieve your need.

vyaningymsft_0-1722411013595.png

DAX:

 

Plus/Minus $ Range by Project Column =
VAR __BASELINE_VALUE =
    CALCULATE (
        SUM ( 'Table'[Estimate $] ),
        FILTER ( 'Table', 'Table'[Project] = EARLIER ( 'Table'[Project] ) )
    )
VAR __VALUE_TO_COMPARE =
    CALCULATE (
        SUM ( 'Table'[Actual $] ),
        FILTER ( 'Table', 'Table'[Project] = EARLIER ( 'Table'[Project] ) )
    )
VAR _difference =
    IF (
        NOT ISBLANK ( __VALUE_TO_COMPARE ),
        DIVIDE ( __VALUE_TO_COMPARE - __BASELINE_VALUE, __BASELINE_VALUE )
    )
VAR _plusMinus =
    SWITCH (
        HASONEVALUE ( 'Table'[Estimate $] ),
        _difference <= -0.3
            && _difference > -0.4, "+/- 30%",
        _difference <= -0.2
            && _difference > -0.3, "+/- 20%",
        _difference <= -0.1
            && _difference > -0.2, "+/- 10%",
        _difference <= 0.05
            && _difference > -0.1, "+/- 5%",
        _difference >= 0.05
            && _difference < 0.1, "+/- 5%",
        _difference >= 0.1
            && _difference < 0.2, "+/- 10%",
        _difference >= 0.2
            && _difference < 0.3, "+/- 20%",
        _difference >= 0.3
            && _difference < 0.4, "+/- 30%",
        "+/- 40% or more"
    )
RETURN
    _plusMinus

 

Count = 
COUNTROWS('Table')

% Overall = 
VAR _allCounts = CALCULATE(COUNTROWS('Table'),ALL('Table'))
VAR _result = DIVIDE([Count],_allCounts)
RETURN
_result

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

@v-yaningy-msft 

unfortunately the sample table and output is incorrect as it is evaluating every row in the table

Batman_powerbi_0-1722462931057.png 

Batman_powerbi_1-1722463227545.png

 

possibly i wasnt clear in my inital post
i wish to calculate and evaluate the Plus/Minus category against Project and Function separately

so in your sample, if i were to calculate this, there should be only a count of 3 total allocated to the %
if i were to do it by Role, i would have a count of 4 total due to the 4 separate roles.



Batman_powerbi
Frequent Visitor

@bhanu_gautam 

Any further thoughts were i might be going wrong?

bhanu_gautam
Super User
Super User

@Batman_powerbi , Create a measure for categorizing the difference on the basis of your difference measure

Difference Category =
SWITCH(
TRUE(),
[Difference $] <= -0.3, "-30% or less",
[Difference $] <= -0.2, "-20% to -30%",
[Difference $] <= -0.1, "-10% to -20%",
[Difference $] <= 0.1, "-10% to 10%",
[Difference $] <= 0.2, "10% to 20%",
[Difference $] <= 0.3, "20% to 30%",
"30% or more"
)

 

Then one more measure for count of category

Count of Categories =
COUNTROWS(
    FILTER(
        'Closed (TABLE)',
        [Difference Category] = EARLIER([Difference Category])
    )
)
 
And then one for percentage
Percentage of Categories =
DIVIDE(
    [Count of Categories],
    COUNTROWS('Closed (TABLE)')
)



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam 

thankyou for the help

when i create the 2nd measure i obtain an error

"EARLIER/EARLIEST refers to an earlier row context which doesn't exist."

which i am not 100% what that means
any thoughts?

@Batman_powerbi , The issue is we have used measure instead of column

 

Create a caluclated column by going to modelling tab

Difference Category =
VAR diff = 'Closed (TABLE)'[Difference %]
RETURN
SWITCH(
TRUE(),
diff <= -0.3, "-30% or less",
diff <= -0.2, "-20% to -30%",
diff <= -0.1, "-10% to -20%",
diff <= 0.1, "-10% to 10%",
diff <= 0.2, "10% to 20%",
diff <= 0.3, "20% to 30%",
"30% or more"
)

 

Then create a measure 

Count of Categories =
COUNTROWS(
FILTER(
'Closed (TABLE)',
'Closed (TABLE)'[Difference Category] = MAX('Closed (TABLE)'[Difference Category])
)
)

 

and last for percentage

DAX
Overall % =
VAR totalRows = COUNTROWS('Closed (TABLE)')
VAR categoryCount = [Count of Categories]
RETURN
DIVIDE(categoryCount, totalRows, 0)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






thanks @bhanu_gautam 

unfortunately i get a duplication of the count of each time the Project is listed in the data table 

Batman_powerbi_0-1722318132990.png

the true nature of the output should be like below,

 

Batman_powerbi_2-1722318237811.png

 

 

Update measure
Count of Categories =
CALCULATE(
COUNTROWS('Closed (TABLE)'),
ALLEXCEPT('Closed (TABLE)', 'Closed (TABLE)'[Difference Category])
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam 
sorry again that is still giving me a duplicate of counts 

i believe its due to the initial calculated column instead of being a measure
- as a column the calculation then assigns a calculation to every row in the table, rather than a rolled up level by project/function




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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