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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculation

Hi everyone,

 I am trying to have my data at 1130 pm to minus data at 12 am on the same day. I dont know how to code that, sorry as i am  new to microsoft power bi.

In a separate column, i had these data extracted:

At 1130 = IF ([TimeKeys] =2330,'Main Data'[Energy (kWh)],BLANK())
At 12am = IF ([TimeKeys] =0000,'Main Data'[Energy (kWh)],BLANK())
 
Now, I am trying to get value at 1130PM to minus value at 12AM of the same day only

However, this is what i get if i directly minus both parameters:

sabrina_az_0-1641484165503.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Sample data

vstephenmsft_0-1641886763884.png

 

Here's my solution.

Create the following measures.

At 1130 PM =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER ( 'Table', FORMAT ( [Date/Time], "HH:MM:SS" ) = "23:30:00" )
)
At 12AM =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER ( 'Table', FORMAT ( [Date/Time], "HH:MM:SS" ) = "00:00:00" )
)
Subtraction =
VAR _1130PM =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            FORMAT ( [Date/Time], "HH:MM:SS" ) = "23:30:00"
        )
    )
VAR _12AM =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            FORMAT ( [Date/Time], "HH:MM:SS" ) = "00:00:00"
        )
    )
RETURN
    _1130PM - _12AM

vstephenmsft_1-1641886882128.png

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
parry2k
Super User
Super User

@Anonymous can you paste data in the table format (instead of image) and the expected output. Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Oh i am sorry, i am rather new here so i am not sure how to copy the table.

Expected output

Date/TimeAt 1130 PMAt 12AMSubtraction
22/1/22 11:30:00PM150 105
22/1/22 12:00:00AM 45 
Anonymous
Not applicable

Hi @Anonymous ,

 

Sample data

vstephenmsft_0-1641886763884.png

 

Here's my solution.

Create the following measures.

At 1130 PM =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER ( 'Table', FORMAT ( [Date/Time], "HH:MM:SS" ) = "23:30:00" )
)
At 12AM =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER ( 'Table', FORMAT ( [Date/Time], "HH:MM:SS" ) = "00:00:00" )
)
Subtraction =
VAR _1130PM =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            FORMAT ( [Date/Time], "HH:MM:SS" ) = "23:30:00"
        )
    )
VAR _12AM =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            FORMAT ( [Date/Time], "HH:MM:SS" ) = "00:00:00"
        )
    )
RETURN
    _1130PM - _12AM

vstephenmsft_1-1641886882128.png

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.