March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi, I am trying to get percentage in power Bi by dividing items designated as line 2 by the same items amount designated as line 1, and when there is no match of items like in scenario of Other the item amount would be divided by Total Line 1. The data table looks the same as the example without the percent's
Line | Item | Sales | Percent |
1 | Water | 6000 | |
1 | Orange | 5000 | |
1 | Apple | 5000 | |
1 | Total | 16000 | |
2 | Water | 540 | 9.00% |
2 | Orange | 286 | 5.72% |
2 | Apple | 975 | 19.50% |
2 | Other | 650 | 4.06% |
Thanks
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Percent CC =
IF (
Data[Line] = 2,
VAR _lineonesales =
SUMX (
FILTER ( Data, Data[Item] = EARLIER ( Data[Item] ) && Data[Line] = 1 ),
Data[Sales]
)
VAR _linetwosales = Data[Sales]
VAR _lineonetotalsales =
SUMX ( FILTER ( Data, Data[Item] = "Total" && Data[Line] = 1 ), Data[Sales] )
VAR _result =
DIVIDE ( _linetwosales, _lineonesales )
RETURN
FORMAT (
IF (
ISBLANK ( _result ),
DIVIDE ( _linetwosales, _lineonetotalsales ),
_result
),
"#,#0.00%"
)
)
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.
Thank you, this is great.
😀
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Percent CC =
IF (
Data[Line] = 2,
VAR _lineonesales =
SUMX (
FILTER ( Data, Data[Item] = EARLIER ( Data[Item] ) && Data[Line] = 1 ),
Data[Sales]
)
VAR _linetwosales = Data[Sales]
VAR _lineonetotalsales =
SUMX ( FILTER ( Data, Data[Item] = "Total" && Data[Line] = 1 ), Data[Sales] )
VAR _result =
DIVIDE ( _linetwosales, _lineonesales )
RETURN
FORMAT (
IF (
ISBLANK ( _result ),
DIVIDE ( _linetwosales, _lineonetotalsales ),
_result
),
"#,#0.00%"
)
)
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.
Hi Jihwan,
Would you have idea how to fix the % on the subtotal line?
Thanks Z
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
18 | |
16 | |
13 |