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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ING_BT
Helper I
Helper I

Divide and Filter by Row condition

Hello ! 

I'm trying a simple calculation - I can't quite figure it out

 

In the example below - I need a measure whith divides the sum ONLY when the ROW SUM is higher than 500.

 

If I do a "If volume B is higher than 500" it will show the others as blank - but it doesn't changes the total value (which should be 5% instead of 1%). 

 

Note:

  • The volume A and the volume B are from different tables.
  • They are both linked to a "Letters" table (one to many relationship - as both tables have multiple dimensions).
  • The measure devides B by A 
  • Both Volume B and A are simple SUM measures

ING_BT_0-1674154236625.png

LettersVolume AVolume BMeasure (Divide)
A              1,532            57638%
B           21,656            5052%
C              2,165            37617%
D              1,651            1258%
E           21,516               780%
F         161,613                 50%
Total         210,133         1,6651%
Only if > 500           23,188         1,0815%

 

I hope my example is clear ! 

 

Thank you for you help!

 

All the best,

BT

4 REPLIES 4
ING_BT
Helper I
Helper I

Hello ! 

Thank you both for your help ! 


But, I think this doesn't quite apply as here it considers that Volume A and Volume B are in the same table which is not the case: 

TableA[VolumeA] + Column LettersA
TableB[VolumeB] + Column Letters B
TableC[Letters]

Table C connects to TableA and TableB via "Letters" in a One to Many relationship on both. 

I've tried to adapt the measure - 

Thank you again! 

Best,
BT

Ok, you would have added sample.

Try this:

sevenhills_1-1674251849016.png

Add these Measures to corresponding tables like in the model above.

Sum of Volume A = Sum('Table GT 500 - A'[Volume A])

Sum of Volume B = Sum('Table GT 500 - B'[Volume B])

Measure Divide = DIVIDE([Sum of Volume B], [Sum of Volume A], 0.00)

Measure Divide 2 = 
      var _bTable = FILTER('Table GT 500 - B', [Sum of Volume B] > 500)
      var _b = CALCULATE([Sum of Volume B], _bTable)
      var _a = CALCULATE([Sum of Volume A],  _bTable, all('Table GT 500 - A') )
      RETURN DIVIDE(_b, _a, 0.00)

 

Output

 

sevenhills_2-1674251951062.png

 

v-cgao-msft
Community Support
Community Support

Hi @ING_BT ,

 

Please try:

Measure = 
IF(
    HASONEVALUE('Table'[Letters]),
    DIVIDE([Sum of Volume B],[Sum of Volume A]),
    VAR _B = 
    SUMX(
        FILTER(
            SUMMARIZE(
                'Table',
                'Table'[Letters],
                "B",[Sum of Volume B]
            ),
            [B]>500
        ),
        [B]
    )
    VAR _A =
    SUMX(
        FILTER(
            SUMMARIZE(
                'Table',
                'Table'[Letters],
                "A",[Sum of Volume A],
                "B",[Sum of Volume B]
            ),
            [B]>500
        ),
        [A]
    )
    RETURN
    DIVIDE(_B,_A)
)

vcgaomsft_0-1674185325402.png

Best Regards,
Gao

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

sevenhills
Super User
Super User

I am not sure the requirement as it is little confusing. I would like provide below details, so that it help you resolve.

 

Power Query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY67DcAwCAVXiagp8rDAafNdAnn/NWI5KWIcyuP0dO60EtPUHViTBKrZqLDT1nMBm1p0Z23uPiwLwzTQ9C4fPx2mCBTybJ9DhyJ21MtLs6/vB1aHkUa5llMpNw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Letters = _t, #"Volume A" = _t, #"Volume B" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Letters", type text}, {"Volume A", Int64.Type}, {"Volume B", Int64.Type}})
in
    #"Changed Type"

 

sevenhills_0-1674183716140.png

Add all measures using Dax:

 

Divide Measure = DIVIDE([Sum B], [Sum A], 0.00)

Divide Measure 2 = DIVIDE([SUM B GT 500], [SUM A GT 500], 0.00)

Is GT 500 = IF ( HASONEVALUE('Table GT 500'[Letters]), If ( [Sum B] > 500, 1, 0), BLANK())

Sum A = Sum('Table GT 500'[Volume A])

SUM A GT 500 = 
   -- only for those [Sum B] gt 500
   IF ( HASONEVALUE('Table GT 500'[Letters]), If ( [Sum B] > 500, [Sum A], BLANK()), 
             CALCULATE([Sum A], Filter('Table GT 500', [Sum B] > 500))
    )

Sum B = Sum('Table GT 500'[Volume b])

SUM B GT 500 = 
    IF ( HASONEVALUE('Table GT 500'[Letters]), If ( [Sum B] > 500, [Sum B], BLANK()), 
            CALCULATE([Sum B], Filter('Table GT 500', [Sum B] > 500))
    )

 

Set the both divide measures format as percentage

 

Output:

sevenhills_1-1674183939725.png

 

sevenhills_2-1674183950061.png

sevenhills_3-1674184018361.png

 

 

Now, you can refine to your needs! Mark it as answered if it helps you. (and Kudos)

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.