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
Anonymous
Not applicable

data in column formula

Hello,

 

I have recorded data time by event like showed below. I would like to get the % of RUN as RUN/(RUN+CHANGE). I do not manage to get it done using DAX

EventDuration (h)
RUN3
STOP15
CHANGE0
RUN12
STOP8
CHANGE8
RUN0
STOP1
CHANGE2
RUN10
STOP14
CHANGE11
2 ACCEPTED SOLUTIONS
MartynRamsden
Solution Sage
Solution Sage

Hi @Anonymous 

 

Try this:

% Run = 
VAR TotalRun =
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "RUN"
)
VAR TotalChange = 
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "CHANGE"
)
VAR Result = DIVIDE ( TotalRun, ( TotalRun + TotalChange ) )
RETURN Result

 

You'll need to replace the reference to Table1 with your actual table name.

 

Best regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

View solution in original post

Hi @Anonymous 

 

If the denominator is always the sum of the selected event + the sum of the "CHANGE" event, then the expression below should work for you:

 

% Selected Event = 
VAR SelEvent = SELECTEDVALUE ( Table1[Event] )
VAR TotalSelEvent =
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = SelEvent
)
VAR TotalChange = 
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "CHANGE"
)
VAR Result = DIVIDE ( TotalSelEvent, ( TotalSelEvent + TotalChange ) )
RETURN Result

 

If you require something different, please provide more info and I'll be happy to help.


Best regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

View solution in original post

5 REPLIES 5
MartynRamsden
Solution Sage
Solution Sage

Hi @Anonymous 

 

Try this:

% Run = 
VAR TotalRun =
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "RUN"
)
VAR TotalChange = 
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "CHANGE"
)
VAR Result = DIVIDE ( TotalRun, ( TotalRun + TotalChange ) )
RETURN Result

 

You'll need to replace the reference to Table1 with your actual table name.

 

Best regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

Anonymous
Not applicable

Thanks a lot!

 

Another question, as I have much more than 3 events, could it be possible to replace the manual typing in the formula by a link to dropdown list or slicer?

 

 Table1[Event] = "RUN" => replaces the "RUN" by a link to slicer?

Hi @Anonymous 

 

If the denominator is always the sum of the selected event + the sum of the "CHANGE" event, then the expression below should work for you:

 

% Selected Event = 
VAR SelEvent = SELECTEDVALUE ( Table1[Event] )
VAR TotalSelEvent =
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = SelEvent
)
VAR TotalChange = 
CALCULATE (
    SUM ( Table1[Duration (h)] ),
    Table1[Event] = "CHANGE"
)
VAR Result = DIVIDE ( TotalSelEvent, ( TotalSelEvent + TotalChange ) )
RETURN Result

 

If you require something different, please provide more info and I'll be happy to help.


Best regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

Anonymous
Not applicable

Hello,

When I create the measure :

VAR TotalSelEvent = CALCULATE(sum('Performance Event Listing'[Durée (h)]),'Performance Event Listing'[Arrêt reclassifié ]=[VAR SelEvent])

I have an error message: A function calculate has been used in a true/false expression that is used as a table filter expression. this is not allowed

 

Hi @Anonymous 

 

My previous answer should be added to your model as a single measure to give you the % of the selected event type vs,  the total.

 

If you want to add a new measure to calculate the total for the selected event type, use this:

Selected Event Total = 
VAR SelEvent = SELECTEDVALUE ( 'Performance Event Listing'[Arrêt reclassifié] ) 
VAR Result =
CALCULATE (
    SUM ( 'Performance Event Listing'[Durée (h)] ),
    'Performance Event Listing'[Arrêt reclassifié] = SelEvent
)
RETURN Result

 

Best regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution.

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.