I need to sum of different suppliers by produt_id, below is an example of table:
product_id
supplier
1
A
1
B
2
A
2
C
2
C
3
D
4
A
4
B
4
B
4
E
4
E
5
C
5
F
5
F
In the table I have other elements, but these columns are the relevant ones for the count.
The answer I'm looking for is 10, I try to explain in the table below:
product_id
DistinctCount(supplier)
1
2
2
2
3
1
4
3
5
2
Total = 2 + 2 + 1 + 3 + 2 = 10
Thanks in advance!
I tried several different ways and I couldn't. I hope I can solve my problem.
These 2 measures will solve your problem
Count Supplier = DISTINCTCOUNT('Table'[supplier])
and
Sum Count Supplyer =
SUMX(
DISTINCT( 'Table'[product_id] ),
[Count Supplier]
)
The Total of Count Supplier is the number of distinct suppliers in the whole table, ignoring the grouping.
I am quite new to Power BI and now facing a problem, illustrated below.
Here
**DATA**
LEVEL | PROJECT NAME| BUDGET_TYPE | BUDGET_CODE | BUDGET_AMOUNT
1 xxxx A 0000001 4,800,000
1 xxxx A 0000002 4,300,000
1 xxxx A 0000002 900,000
1 A 0000003 1,300,000
1 A 0000004 4,780,000
1 A 0000010 3,900,000
1 A 0000010 3,900,000
1 A 0000011 200,000
1 A 0000015 1,028,165
1 A 0000015 1,028,165
1 B 0000016 83,000,000
1 B 0000017 83,000,000
1 B 0000017 28,200,000
1 B 0000018 15,000,000
1 B 0000019 4,800,000
1 B 0000020 7,000,000
1 B 0000020 7,000,000
PIVOT TABLE from Excel
Row Labels | Max of BUDGET_AMOUNT
LEVEL: 1 83,000,000
TYPE:A 4,800,000
0000001 4,800,000
0000002 4,300,000
0000003 1,300,000
0000004 4,780,000
0000010 3,900,000
0000011 200,000
0000015 1,028,165 **20,308,165**
TYPE:B 83,000,000
0000016 83,000,000
0000017 83,000,000
0000018 15,000,000
0000019 4,800,000
0000020 7,000,000 **192,800,000**
Grand Total 83,000,000
I have raw data and PIVOT TABLE, respectively. What I want is to find MAX amount of each CODE first.
Then, SUM those MAX values only with distinct CODE.
I have attached the PIVOT TABLE for simplifying my problem. What I really want at the end is the SUM amount which is
LEVEL 1
TYPE A: 20,308,165
TYPE B: 192,800,000
Is there any way I can do that? Please help. Thanks!
You can do a measure that summarizes the different codes, calculates the max for each code, and sums up this table row-by-row:
Sum :=
VAR _tbl =
SUMMARIZE (
'Table' ,
'Table'[Level] ,
'Table'[Budget Code] ,
"Max Budget" , CALCULATE ( MAX ( 'Table'[Budget] ) )
)
RETURN
SUMX ( _tbl , [Max Budget] )
See minimal data example here:
Need help in creating measures that will reflect the actual count of rows in the table when filtered.
Example:
ID
RankC
RankA
Avg Diff
RankC_count
RankA_count
Avg Diff_count
1000
AAA
XYZ
+01.00 to +01.25
5
6
4
1001
AAA
ZY1
+01.5.00 to +01.75
5
1
5
1002
AAB
XYZ
+01.5.00 to +01.75
3
6
5
1003
AAB
ZY2
+01.5.00 to +01.75
3
1
5
1004
AAB
XYZ
+01.00 to +01.25
3
6
4
1005
AAA
XYZ
+01.00 to +01.25
5
6
4
1006
AAA
ZY3
+01.00 to +01.25
5
1
4
1007
AAC
XYZ
+01.25.00 to +01.5
1
6
2
1008
AAA
ZY4
+01.25.00 to +01.5
5
2
2
1009
AAZ
ZY4
+01.5.00 to +01.75
1
2
5
1010
ABY
XYZ
+01.5.00 to +01.75
1
6
5
The last 3 columns represent the count of each entry. If I use the measure such as below, it provides the correct count. However, when I use in the visual, filtering by ID, say ID 1000, I want it to show line 1 with 5,6, and 4 on the counts, instead of all 1.
Questions:
Is there any measure to give me the correct result? say summarize the table first then do a lookup?
is creating a column the only choice? I cannot create columns since I need 1000 of these calculated columns. whereas using measure, I can create 1000 in one go.
Thanks for any help.
AverageDiff_Count =
CALCULATE (
COUNTROWS (
FILTER ( '28Jun_1973', [Average Diff] = '28Jun_1973'[Average Diff] )
)
)
The ALL function is useful here. It removes filter context so that it uses the whole table instead of just the part in the current filter context.
AvgDiff_Count =
VAR CurrAvgDiff = SELECTEDVALUE ( '28Jun_1973'[Avg Diff] )
RETURN
COUNTROWS (
FILTER ( ALL ( '28Jun_1973' ), '28Jun_1973'[Avg Diff] = CurrAvgDiff )
)
i have a 2 tables that looks like this
Key |Num Of Treatments| Cost |
1 2 1000
1 2 1500
1 2 2000
2 3 700
3 3 800
4 4 900
key | limit |
1 1
2 1
3 2
4 3
the calculation that i want to do on dax is : (Num Of Treatments-Limit)*cost/Num Of Treatments
Assuming that the key column is unique for the second table (Table2 in dax).
Calculation =
VAR _limit =
LOOKUPVALUE ( Table2[limit], Table2[key], [key] )
RETURN
DIVIDE ( ( [Num Of Treatments] - _limit ) * [cost], [Num Of Treatments] )
This can be easily be achieved after creating one to many relationship between two tables with column Key.
Dax formula :
New Measure = ((SUM(Asset[No Of Treatments])-SUM(Tickets[Limit]))*SUM(Asset[Cost]))/SUM(Asset[No Of Treatments])
I am struggling to get this going and could need some help. I have the following setup:
Order Item Material Value
22 1 100 27,5
22 1 200 27,5
22 1 300 27,5
22 2 100 33
22 3 500 101
26 1 500 88
26 1 600 88
I have duplicate values becaue of the Material, so I want to group by Order, Item and Value and then calculate the total Value in a DAX measure.
After grouping:
Order Item Value
22 1 27,5
22 2 33
22 3 101
26 1 88
The final Value:
Total Measure = 249,5
I tried the following DAX expression for the Total Measure:
Total Measure = Summarize('Table1'; 'Table1'[Order]; 'Table1'[Item]; "Sum Value:"; Sum('Table1'[Value]))
It gives me the error:
Multiple columns cannot be converted to a scalar value
So I tried:
Total Measure = Sumx('Table1'; Summarize('Table1'; 'Table1'[Order]; 'Table1'[Item]; "Sum Value:"; Sum('Table1'[Value])))
But this didnt work either. For every help thanks in advance.
The following code should be what you are looking for
Measure1 =
SUMX (
SUMMARIZE (
Table1;
Table1[Order];
Table1[Item];
Table1[Value];
"TotalSum"; SUM ( Table1[Value] )
);
[Value]
)
In this case, you can simply use the VALUES function instead of SUMMARIZE.
Total Measure = SUMX ( VALUES ( Table1[Value] ), [Value] )
This iterates over each unique Value and adds Value to the sum.