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.
Related
I have these columns and I want to create a measure to calculate the number of types
types
ID Type
1 A
2 A
3 B
4 C
5 D
6 A
7
8
Results :
A 3
B 1
C 1
D 1
Blank 2
Try this Calculated Table:
Results =
SUMMARIZE(
'Table',
'Table'[Type],
"Count", COUNT('Table'[ID])
)
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 new to Latent Class Analysis in SAS and probably this would be a silly question to ask, but I cannot understand why my item response probabilities change when I switch the order of the items included in the item statement?
Everything else in my syntax stays the same, including a fixed seed number.This has been so frustrating...Thank you!
If running code 1, I w'd get item1 response probabilities such as: class 1 (0.9961), class 2 (0.1156), class 3 (0.9401), class 4 (0.7769) whereas when running code 2, I get for the same item: class 1 (0.9513), class 2 (0.4307), class 3 (0.7870), class 4 (0.5731). Why would the order matter?
SAS Code 1.
/*here is a normal order of items*/
items item1 item2 item3 ... item23; /*from item1 through item23*/
categories 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ;
RHO PRIOR=1;
seed 123741;
run;```
CODE 2 - exactly same code with exactly same items but in a different order in the item statement:
proc lca data = lca OUTPARAM = testapp outpost = lcapp_post;
nclass 4;
id qid;
/*here is another order of SAME items listed in code#1*/
items item3 item21 item20 item22 item19 item10.../*and the rest*/ ;
categories 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ;
RHO PRIOR=1;
seed 123741;
run;
In my data, income was asked only to one person of the group.
householdID memberID income
1 1 4
2 2 .
1 2 .
2 3 .
2 1 3
But obviously, I need to fill them up like
householdID memberID income
1 1 4
2 2 3
1 2 4
2 3 3
2 1 3
How can I do this in Stata?
This is an elementary application of by:
bysort householdID (income) : replace income = income[1] if missing(income)
See for related material this FAQ
A more circumspect approach would check that at most one non-missing value has been supplied for each household:
bysort householdID (income) : gen OK = missing(income) | (income == income[1])
list if !OK