Power BI - Dax - Average - powerbi

I have table like this:
Client_ID/Type_of_product/Product_ID
C1/A/P1
C1/B/P2
C2/A/P3
I would like to filter by Type_of_product and calculate number of products (in total) per client.
When I filter A, there is 2 clients(C1 and C2), who have 3 products in total. So answer is 1,5
When I filter B, there is 1 client (C1) which has 2 products in total. So answer is 2.
Please could anyone advise me?
Many thanks :)
roman

Please try this DAX Measure: you need to manipulate filter context to achieve your result.
Average NOProducts Per Customer =
DIVIDE(
CALCULATE(COUNT(GTA[Product_ID]),ALL(GTA), VALUES(GTA[Client_ID])),
CALCULATE(DISTINCTCOUNT(GTA[Client_ID]))
)
If we test it on a table visual:

Related

DAX - DISTINCTCOUNT based on measure

I have the following dataset:
and the following measures:
Count of Filters = if(ISFILTERED(Table1[Product]), COUNTROWS(FILTERS (Table1[Product])), 0)
Count = if(ISFILTERED(Table1[Product]), COUNT(Table1[Unique_ID]),0)
What I would like to to is, when I filter the table at Product, that a measure disctinct counts the unique_ID that have a count equivalent to the count of filters.
The following should be able to explain better:
When filtering to product 1, A list of all appear, because they all have product 1:
But when also selecting Product 2, A and B have a total count of 2 because they have entries for both product 1 and 2.
Now, what I ultimately want, is a measure that can do a distinctcount on only the Unique_ID that have the Count equal the count of filters. In the above scenario, I would want the total to give me 2 (as only UNIQUE_ID A and B have both products 1 and 2).
I have put together the following:
Total = CALCULATE(DISTINCTCOUNT(Table1[Unique_ID]),FILTER(Table1, Table1[Count]=Table1[Count of Filters]))
but this doesn't seem to work. I understand why it's not working, but I can't seem to figure out how to put together a measure to calculate this for me.
Many thanks in advance!

Power BI: Calculate percentage of by category from the same column

I would like to calculate a percentage from a column and save it in a card for a Power BI dashboard. The column is as below:
index header-"grade"
1 pass
2 failed
3 pass
4 partly-pass
5 pass
6 failed
7 partly-pass
...
I want to calculate the percentage of count of 'failed'/total count of the column, then put the percentage in the card, can someone help please? I am a complete Power BI newbie here.
thanks
solved it:
% of category =
DIVIDE(
CALCULATE(COUNTROWS(Tablename), Tablename[column] = 'category'),
COUNTROWS(Tablename)
)

Measure (CALCULATE) - two fact tables

Hi DAX Experts around the world,
I hope you can help me with below problem. In short:
there are two fact tables: Table1 and Table2 , not connected between each other and cannot be appended.
they have both relation to Calendar table
I need to create a measure which will return some part from Table1 and a part form Table2, as described on the picture.
When a Nov-21 is selected on the slicer, measure should return Actuals for first 10 months of the year with 100 each month (from Table1) and remaining 2 months with Forecast values from with 200 each month (from Table2).
Is it possible at all as I am out of ideas ?
Thank you in advance.
Max
You can create a copy of the calendar table(Calender (2)), which can be used to create a slicer.
With the help of this table, you can create a measure to calculate the value based on selected date like this:
Amount Measure =
VAR _selected_date = MAX('Calender (2)'[Date])
return SUMX(SUMMARIZE(Calender,Calender[Date]),IF('Calender'[Date]<_selected_date,SUMX(FILTER(Table1,Table1[Version]="Actual"),[Amount]),SUM(Table2[Amount])))

Calculating the percentage of grand total by category with DAX for one category only

I need help calculating the percentage of each category in a column (based on the grand total) in DAX but for one specific category.
This is how the data is structured. Each row is an individual transaction with an ID column and item column.
I need to get the % of transactions that are for bagels only. This is my sql code I currently use.
`Select 100 - CAST(count([Items])
- count(case [Items] when 'Bagel' then 1 else null end) AS FLOAT)
/ count([Items]) * 100 as Percent_Bagel
from Items_Table where Items != 'Coffee'
and Items != 'Muffin'`
I need this to be converted to a DAX formula to use in a Power BI measure if possible, but I am new to DAX and don't know where to begin.
Thank you.
The "right" implementation for you always depends on the context. You can achieve your goal through different approaches.
I have used the following:
Measure =
DIVIDE(
-- Numerator: Filter all Bagel's transaction and count them
CALCULATE(
COUNT('Table'[Transaction ID]),
FILTER('Table', 'Table'[Item] = "Bagel")
),
-- Denominator: Remove any filter - essentially fixing the full table - and count all transactions we have
CALCULATE(
COUNT('Table'[Transaction ID]),
ALL('Table'[Item])
),
-- If something goes wrong with the DIVIDE, go for 0
0
)
You may also use the filters to rule out all measures that are not blank.
Without measure filter
With measure filter (Other categories are gone)
Hope this is what you are looking for!

LOOKUPVALUE + SUM Q

I would like sum in a lookupvalue. Is that possible or is there another command(s) that I need to look at to achieve my desired outcome?
I have a budget table with a field and would like to scan a transaction table with the same field name. How do I sum all the transactions and put the total into the budget table?
I am wanting to sum the transactions to the corresponding field(s) in the Budget Table.
This is my first time answering to StackOverflow and I hope I get this right.
From my understanding, you want to sum the _amt value from the Transaction Table into the Budget Table in Power BI using Dax. In the Budget Table, what you can do is the following:
Sum_amt_2018 = CALCULATE(SUM('Transaction Table'[_amt]),FILTER('Transaction Table', 'Transaction Table'[_link] = 'Budget Table'[_link]))
Hope this helps.