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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
jpaguiar
Frequent Visitor

Divide Prior to SumX

Hi folks,

It might a simple task, but I've tried to create the Aux_Column using several different combinations of Calculate, SumX, Divide, Filter, FirstNonBlank, among others but no lucky.
My goal is to have for each IDs in the 'Cycle' column the result of 'Running' / 'Waiting' rows of the 'Driver' column using values from the 'Actual' column. For instance, for Cycle = A, all rows should be 4 (120/30), while for Cycle = B they should be 11.67 (140/12), etc. The issue is that the Cycle column is present only in the raw data, not in the summary table in the visual, therefore when aggregating values for the Aux_Column, most formulas that I've tried are performing 120 + 140 and then dividing by 30 + 12.

Thanks in advance for any help.

DriverActualCycleAux_Column
Running120A4
Jogging50A4
Waiting30A4
Running140B11.67
Jogging25B11.67
Waiting12B11.67

 

2 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

hi @jpaguiar 

try like:

Column =
VAR _table=
FILTER(
    TableName,
    TableName[Cycle]=EARLIER(TableName[Cycle])
)
VAR _running = 
SUMX(
    FILTER(
        _table,
        TableName[Driver]="Running"
    )
    TableName[Actual]
)
VAR _waiting = 
SUMX(
    FILTER(
        _table,
        TableName[Driver]="Waiting"
     ),
    TableName[Actual]
)
RETURN DIVIDE(_running, _waiting)
 
it worked like:
FreemanZ_0-1680869078557.png

View solution in original post

@jpaguiar 
Yes you are right. Seems like the context transition effect of the SUMMARIZE function is creating a filter context issue that is not easy to understand. Replacing SUMMARIZE with GROUPBY solves the problem

1.png

View solution in original post

7 REPLIES 7
jpaguiar
Frequent Visitor

Hi there @FreemanZ @tamerj1!

You guys have helped me a lot to progress with the data transformation steps that I am having to do in order to create an interactive dashboard, however I got into a new roadblock.

If you have the chance, could you please take at this new challenge?

DriverActualTargetCycle
Running120100A
Jogging5040A
Waiting3010A
Running140110B
Jogging2530B
Waiting1220B


I was able to use the proposed solutions to summarize the original table to this aggragated one on which I don't need to specificy the metrics for each Cycle.

DriverActualTargetDeltaR_ActualR_TargetDiff TargetFactorR_Delta
Running130.0105.025.0112.0140.035.00.3333338.33
Jogging37.535.02.541.040.0  0.83
Waiting21.015.06.027.025.0  2.00


From the original Actual and Target values, I re-calculated them after some data transformation to get R_Actual and R_Target. Then I calculated a measure that is the difference between R_Target and Target but only for Driver = "Running". Then I created another measure (Factor) so that I could use this factor for re-calculating the data column proportionaly (R_Delta). My issue is that I am unable to pass the factor 0.33 resulting from the measure Factor to all rows to then multiply it by the Target column values for all rows to get 0.83 and 2.00. PowerBI does the multiplication row by row, therefore it shows empty cells for R_Delta for Jogging and Waiting Rows.

Thank you so much in advance!

Hi @jpaguiar 
PLease try

Target	Factor 2 =
CALCULATE (
    [Target	Factor],
    'Table'[Driver] = "Running"
)
tamerj1
Super User
Super User

Hi @jpaguiar 
Please refer to attached sample file with the proposed solution

1.png

Measure = 
VAR T1 = CALCULATETABLE ( 'Table', ALLSELECTED ( 'Table' ), VALUES ( 'Table'[Cycle] ) )
VAR T2 = SUMMARIZE ( T1, 'Table'[Driver], "@SUM", SUM ( 'Table'[Actual] ) )
RETURN
    PRODUCTX ( 
        T2, 
        SWITCH (   
            'Table'[Driver],
            "Running", [@SUM],
            "Waiting", 1/[@SUM]
        )
    )

Hi @tamerj1,

It worked great with no filters applied, but then when I filter either cycle A or cycle B, it apparently tries to calculate the division for each 'Driver' individualy, resulting in 'Infitiny'. If I try to use the same strategy but using a calculated column, it again works for unfiltered views but returns 1.04 for either Cycle = A or Cycle = B filters, which I believe is just calculing the sum prior to the division again.

FreemanZ worked fine for both filtered and unfiltered.
Thank you for the support mate!

@jpaguiar 
Yes you are right. Seems like the context transition effect of the SUMMARIZE function is creating a filter context issue that is not easy to understand. Replacing SUMMARIZE with GROUPBY solves the problem

1.png

FreemanZ
Super User
Super User

hi @jpaguiar 

try like:

Column =
VAR _table=
FILTER(
    TableName,
    TableName[Cycle]=EARLIER(TableName[Cycle])
)
VAR _running = 
SUMX(
    FILTER(
        _table,
        TableName[Driver]="Running"
    )
    TableName[Actual]
)
VAR _waiting = 
SUMX(
    FILTER(
        _table,
        TableName[Driver]="Waiting"
     ),
    TableName[Actual]
)
RETURN DIVIDE(_running, _waiting)
 
it worked like:
FreemanZ_0-1680869078557.png

Hi @FreemanZ,

It worked perfectly for both filtered and unfiltered views!
Superb, man! Thank you!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.