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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Generate new table with calculated rows based on daily MIN and MAX variables

I have an energy dataset and need to insert calculated rows (i.e. figure out the difference between the total and the other variables). I am using this approach: https://community.powerbi.com/t5/Desktop/Insert-custom-rows/m-p/731157#M352721 , i.e. generating a new table with rows and then merging those into the original table using the UNION function. My current solution is very ridgid and only gives me the calculated values for the first and last day of my dataset (which is one month). I would like to be able to see a higher resolution, i.e. calculate the "other" variable each day. I am not sure if I need to generate a row for each day or if it is possible to calculate it dynamically based on report level or other filters. Any suggestions? My current code looks like this:

 

custom rows = 
VAR minTotalVal =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "total"
        )
    )

VAR minSockets1Val =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets1"
        )
    )

VAR minSockets2Val =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets2"
        )
    )

VAR minSockets3Val =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets3"
        )
    )

VAR minLights1Val =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "lights1"
        )
    )

VAR minLights2Val =
    CALCULATE(
        MIN(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "lights2"
        )
    )

VAR maxTotalVal =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "total"
        )
    )

VAR maxSockets1Val =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets1"
        )
    )

VAR maxSockets2Val =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets2"
        )
    )

VAR maxSockets3Val =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "sockets3"
        )
    )

VAR maxLights1Val =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "lights1"
        )
    )

VAR maxLights2Val =
    CALCULATE(
        MAX(September[data.energy]),
        FILTER(
            ALL(September),
            September[location.circuit] = "lights2"
        )
    )

RETURN
    UNION(
        ROW(
            "accountId", LOOKUPVALUE(September[accountId],September[data.energy], minTotalVal),
            "DateInt", LOOKUPVALUE(September[DateInt],September[data.energy], minTotalVal),
            "received", LOOKUPVALUE(September[received],September[data.energy], minTotalVal),
            "TimeKey", LOOKUPVALUE(September[TimeKey],September[data.energy], minTotalVal),
            "data.energy", CALCULATE(
                minTotalVal - minSockets1Val - minSockets2Val - minSockets3Val - minLights1Val - minLights2Val
            ),
            "location.circuit", "others"
        ),
        ROW(
            "accountId", LOOKUPVALUE(September[accountId],September[data.energy], maxTotalVal),
            "DateInt", LOOKUPVALUE(September[DateInt],September[data.energy], maxTotalVal),
            "received", LOOKUPVALUE(September[received],September[data.energy], maxTotalVal),
            "TimeKey", LOOKUPVALUE(September[TimeKey],September[data.energy], maxTotalVal),
            "data.energy", CALCULATE(
                maxTotalVal - maxSockets1Val - maxSockets2Val - maxSockets3Val - maxLights1Val - maxLights2Val
            ),
            "location.circuit", "others"
        )
    )

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I found a nice workaround that works without having to add rows to my table, see here:
https://community.powerbi.com/t5/Desktop/Waterfall-Chart-using-multiple-measures/m-p/643163/highligh...

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I found a nice workaround that works without having to add rows to my table, see here:
https://community.powerbi.com/t5/Desktop/Waterfall-Chart-using-multiple-measures/m-p/643163/highligh...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.