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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
icdns
Post Patron
Post Patron

Per Unit Computation Dax

Hi Guys, 

 

Would need your help in constructing a dax that computes the per unit computation. The computation of Per Unit is (Present value) ÷ (Maximum Data Point) I'm using a date hierarcy (Year, Quarter & Month) and other dimensions. So the maximum data point will depedend on the filters selected. 

 

Expectation: 

The maximum value for this is 999 (September) so we will divide each value by 999. 

Example: 456/999 = 0.46

 

You can play with this Sample pbix: https://www.mediafire.com/file/0pbtogvc6kib02k/sample_powerbi.pbix/file

 

icdns_0-1647498608177.png

 

 

Thank you so much in advance!!

 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @icdns ,

 

I download you sample and have test. Firstly I suggest to to sort [Month] column by [MonthNo] column.

For reference: Sort one column by another column in Power BI Desktop

Then create a measure as below to achieve your goal.

Sales Percentage = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( sampledata ),
        sampledata[Year],
        sampledata[Month],
        sampledata[City],
        "Sales", CALCULATE ( SUM ( sampledata[Sales] ) )
    )
VAR _ADDMAX =
    ADDCOLUMNS (
        _SUMMARIZE,
        "MaxSales", MAXX ( FILTER ( _SUMMARIZE, [City] = EARLIER ( [City] ) ), [Sales] )
    )
VAR _Sales =
    CALCULATE ( SUM ( sampledata[Sales] ) )
VAR _MaxSales =
    MAXX ( FILTER ( _ADDMAX, [City] = MAX ( sampledata[City] ) ), [MaxSales] )
RETURN
    DIVIDE ( _Sales, _MaxSales )

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
icdns
Post Patron
Post Patron

Hi @v-rzhou-msft , 

 

Thank you for this. It is now working when it's on a monthly view. However, in my table I have also Quarter and Year column. If I drill up to yearly and quarterly view the value adds up. (Ex. If the view is Yearly, the value point let say 2016 is the TOTAL per unit of the 12 months (Jan-Dec))

 

The computation must be the same on how we compute with the monthly view wherein (Present value) ÷ (Maximum Data Point) 

 

How can we insert this in the dax? 🙂 

 

Thanks!

 

v-rzhou-msft
Community Support
Community Support

Hi @icdns ,

 

I download you sample and have test. Firstly I suggest to to sort [Month] column by [MonthNo] column.

For reference: Sort one column by another column in Power BI Desktop

Then create a measure as below to achieve your goal.

Sales Percentage = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( sampledata ),
        sampledata[Year],
        sampledata[Month],
        sampledata[City],
        "Sales", CALCULATE ( SUM ( sampledata[Sales] ) )
    )
VAR _ADDMAX =
    ADDCOLUMNS (
        _SUMMARIZE,
        "MaxSales", MAXX ( FILTER ( _SUMMARIZE, [City] = EARLIER ( [City] ) ), [Sales] )
    )
VAR _Sales =
    CALCULATE ( SUM ( sampledata[Sales] ) )
VAR _MaxSales =
    MAXX ( FILTER ( _ADDMAX, [City] = MAX ( sampledata[City] ) ), [MaxSales] )
RETURN
    DIVIDE ( _Sales, _MaxSales )

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

  

Jihwan_Kim
Super User
Super User

Hi,

I hope you can get an idea on how to create a measure from the below picture and the attached pbix file.

 

Picture1.png

 

Per unit measure: =
VAR maxcount =
    CALCULATE ( MAX ( Data[Count] ), REMOVEFILTERS ( Data ) )
RETURN
    DIVIDE ( [Count measure:], maxcount )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

amitchandak
Super User
Super User

@icdns , Assuming count is measure create a measure like this for denominator

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

 

that is what im planning to do. But the problem is i can't get the correct maxmium data point 😞 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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