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

Conditionnal Divide of Sums

Hello,

I have a table like this 

 

Period | Site | Client | Revenue | Expense

202204 | France | X | 1000 | 75

202205 | France | X | 1000 | 100

202205 | UK | Y | 500 | 100

202204 | UK | Z | 0 | 50

 

I'd like to create a measure (ratio in %) that I would explain like this in SQL :

Select SUM(Expense)/SUM(Revenue)

Where Revenue > 0

Group By Period, Client, Site

 

The "Group By" describes the fact this measure should automatically be calculated when I select my filter Period and/or Client and/or Site

 

Any Help would be greatful !

Thx

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Xavier 

 

You can try the following methods.

Measure =
CALCULATE (
    DIVIDE ( SUM ( 'Table'[Expense] ), SUM ( 'Table'[Revenue] ) ),
    FILTER (
        ALL ( 'Table' ),
        [Revenue] > 0
            && [Period] = SELECTEDVALUE ( 'Table'[Period] )
            && [Site] = SELECTEDVALUE ( 'Table'[Site] )
            && [Client] = SELECTEDVALUE ( 'Table'[Client] )
    )
)

vzhangti_0-1654248104909.pngvzhangti_1-1654248121028.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then 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-zhangti
Community Support
Community Support

Hi, @Xavier 

 

You can try the following methods.

Measure =
CALCULATE (
    DIVIDE ( SUM ( 'Table'[Expense] ), SUM ( 'Table'[Revenue] ) ),
    FILTER (
        ALL ( 'Table' ),
        [Revenue] > 0
            && [Period] = SELECTEDVALUE ( 'Table'[Period] )
            && [Site] = SELECTEDVALUE ( 'Table'[Site] )
            && [Client] = SELECTEDVALUE ( 'Table'[Client] )
    )
)

vzhangti_0-1654248104909.pngvzhangti_1-1654248121028.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

amitchandak
Super User
Super User

@Xavier , Try a measure like

 

calculate( divide(SUM(Table[Expense]),SUM(Table[Revenue])), filter(Table, Table[Revenue] >0 ))

 

Group will be what you take in visual

 

DAX vs SQL: https://www.youtube.com/watch?v=WlvQ_SGy4iA&list=PLPaNVDMhUXGZNyKU0PgG2g3P0c6CPjMnj

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
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.