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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ashwinil
New Member

DAX Query help

Power BI Issue.PNG

 

 

PFA, I have the excel dataset as per show in first table of attached snapshot and I want to create power BI chart (table) to display Expense and Gross margin values.
 
I am not sure whether is there any way where I require to do calculation based on the values of columns.
1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @ashwinil,

 

I'd like to suggest you enter to query editor to do unpivot column function on your fields to transform these value filed to attribute and value, then create a matrix visual with measure to achieve your requirement.('for P&L' to row, 'attribute' to column)

Unpivot columns (Power Query)

 

Sample formula:

Measure =
VAR _expense =
    CALCULATE (
        SUM ( Table[Value] ),
        FILTER ( ALLSELECTED ( Table ), Table[Attribute] = "Salary" ),
        VALUES ( Table[For P&L] )
    )
        - CALCULATE (
            SUM ( Table[Value] ),
            FILTER ( ALLSELECTED ( Table ), Table[Attribute] = "Travel" ),
            VALUES ( Table[For P&L] )
        )
RETURN
    IF (
        SELECTEDVALUE ( Table[For P&L] ) = "Expense",
        _expense,
        IF (
            SELECTEDVALUE ( Table[For P&L] ) = "Gross Margin",
            CALCULATE (
                SUM ( Table[Value] ),
                ALLSELECTED ( Table ),
                VALUES ( Table[Attribute] )
            )
                - _expense,
            CALCULATE (
                SUM ( Table[Value] ),
                ALLSELECTED ( Table ),
                VALUES ( Table[Attribute] ),
                VALUES ( Table[For P&L] )
            )
        )
    )

BTW, I have found any expense records in your table, did it real existed in your table? If not, you need to create a custom P&L table with related values, then use that value for calculate.


Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.