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
mohanpal
Frequent Visitor

How to divide values from Same column based on filter

mohanpal_0-1660015372703.png

Hi, I have this sample data. I want to create a column 'Percentage' which should divide based on ID and Year. I did manage to write a query but that is aggreating all the projection value and giving me one single value not vaue for each row. 

1 ACCEPTED SOLUTION
liuqi_pbi
Resolver II
Resolver II

Hi @mohanpal 

 

If you accept a DAX method, you can create a calculated column with below DAX. This will add a new column to the table. 

Percentage =
VAR _projectionA =
    MAXX (
        FILTER (
            'Table',
            'Table'[Id] = EARLIER ( 'Table'[Id] )
                && 'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Label] = "A"
        ),
        'Table'[Projection]
    )
VAR _projectionB =
    MAXX (
        FILTER (
            'Table',
            'Table'[Id] = EARLIER ( 'Table'[Id] )
                && 'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Label] = "B"
        ),
        'Table'[Projection]
    )
RETURN
    DIVIDE ( _projectionA, _projectionB )

 

----------------------------------------------------------------------

If this reply helps solve the problem, please mark it as Solution! Kudos are appreciated too!

View solution in original post

2 REPLIES 2
liuqi_pbi
Resolver II
Resolver II

Hi @mohanpal 

 

If you accept a DAX method, you can create a calculated column with below DAX. This will add a new column to the table. 

Percentage =
VAR _projectionA =
    MAXX (
        FILTER (
            'Table',
            'Table'[Id] = EARLIER ( 'Table'[Id] )
                && 'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Label] = "A"
        ),
        'Table'[Projection]
    )
VAR _projectionB =
    MAXX (
        FILTER (
            'Table',
            'Table'[Id] = EARLIER ( 'Table'[Id] )
                && 'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Label] = "B"
        ),
        'Table'[Projection]
    )
RETURN
    DIVIDE ( _projectionA, _projectionB )

 

----------------------------------------------------------------------

If this reply helps solve the problem, please mark it as Solution! Kudos are appreciated too!

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

remember its recommended to get a quicker answer to show a end result of the result you looking to have, quickly as I can see and understand I recommend you using a "group by" of the power query that lets you decide the operation to be done with a certain value column (sum, divei, multipli, count, etc) and group the operation by giving columns as the 2 you need. 

 

hope this helps of get you a little on your way





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




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.

Top Solution Authors
Top Kudoed Authors