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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Create a new calculated column in matrix

Hi guys, 

I'm quite new with Power Bi and i am using a matrix to group my data like this.

Capture.PNG

Now I want to add a new column which allow me to make a new calculation = ([q'ty per unit of 3rd month] - [q'ty per unit of 2nd month]) * [Price per Unit of 3rd month]

Is there any simple way help me to do so since I'm not an expect with DAX. Thanks for your help.

1 ACCEPTED SOLUTION

@Anonymous ,

 

You can modify the measure above as below:

Result =
VAR qty_per_unit_of_first_month_in_slicer =
CALCULATE ( MIN ( Table[q'ty per unit] ), ALLSELECTED ( Table ) )
VAR qty_per_unit_of_last_month_in_slicer =
CALCULATE ( MAX ( Table[q'ty per unit] ), ALLSELECTED ( Table ) )
VAR Price_per_Unit_of_last_month =
CALCULATE (
MAX ( Table[Price per Unit] ),
FILTER ( Table, Table[Month] = qty_per_unit_of_last_month_in_slicer )
)
RETURN
qty_per_unit_of_last_month_in_slicer - qty_per_unit_of_first_month_in_slicer * Price_per_Unit_of_last_month

 

Community Support Team _ Jimmy 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

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Generally, you can create a measure using DAX like pattern below and drag the measure to the value field:

Result =
VAR qty_per_unit_of_3rd_month =
    CALCULATE ( MAX ( Table[q'ty per unit] ), FILTER ( Table, Table[Month] = 3 ) )
VAR qty_per_unit_of_2rd_month =
    CALCULATE ( MAX ( Table[q'ty per unit] ), FILTER ( Table, Table[Month] = 2 ) )
VAR Price_per_Unit_of_3rd_month =
    CALCULATE ( MAX ( Table[Price per Unit] ), FILTER ( Table, Table[Month] = 3 ) )
RETURN
    qty_per_unit_of_3rd_month - qty_per_unit_of_2rd_month * Price_per_Unit_of_3rd_month

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

@v-yuta-msfthi,

 

It worked for me, in this case i used the slicer to select month 2 to 3, and the DAX you provided also apply to month 2 & 3.

 

How can i change the DAX so that it will be apply directly to the slicer, for example: I selected to compare the month 1 &4 and the Dax Measure also changed to month 1 & 4?

@Anonymous ,

 

You can modify the measure above as below:

Result =
VAR qty_per_unit_of_first_month_in_slicer =
CALCULATE ( MIN ( Table[q'ty per unit] ), ALLSELECTED ( Table ) )
VAR qty_per_unit_of_last_month_in_slicer =
CALCULATE ( MAX ( Table[q'ty per unit] ), ALLSELECTED ( Table ) )
VAR Price_per_Unit_of_last_month =
CALCULATE (
MAX ( Table[Price per Unit] ),
FILTER ( Table, Table[Month] = qty_per_unit_of_last_month_in_slicer )
)
RETURN
qty_per_unit_of_last_month_in_slicer - qty_per_unit_of_first_month_in_slicer * Price_per_Unit_of_last_month

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Send me your pbix to fix it...(I need to see how your tables are)

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.