DAX - DISTINCTCOUNT based on measure - powerbi

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!

Related

Getting correct Sum for total row DAX Power BI

I have:
Dim Table:
Accounts: customer granularity level.
Fact Table:
PhoneCalls. calls to customers granularity level.
I need to create and see the number of calls made to a customer up until the customer made their first deposit.
I was able to do this on the customer level but on the Total level I get a weird result:
my measure:
ACC_Calls_2_FDP =
CALCULATE(
COUNTROWS(PhoneCalls),
PhoneCalls[disposition] = "ANSWERED", -- only calls that were answered
PhoneCalls[calldate] <= MAX(Accounts[FDP_Date]), -- up until FDP date per customer
USERELATIONSHIP(Accounts[AccountNo],PhoneCalls[AccountNo]) -- make the connection active
)
the results are:
On the total level i was expecting to see 14. not 536
what is going on? what am i missing?
The data model:
Filter direction: Accounts filters PhoneCalls
Cardinality 1:*
Power BI doesn't sum up each of the row values as in Excel. Instead, for Grand total value they will still calculate it as a row itself with no filters on AccountNo on it.
In this case, the max value of FDP_Date in the whole table is taken in the measure. So for example, ACC 1 has max date of 3, ACC 3 has the max of 10. The grand total calculation will use 10 as the max value and start countrows on whichever rows with FDP_Date < 10.
To fix this is tricky as I don't have any other information than this. However, I hope this explains you well of the "bug".

PowerBi Distinctcount not working properly with 3 measures

I am having an issue using the Distinctcount function in DAX. I have a table with a total of 1,154,493 rows. I have a measure created to count the number of distinct values in column 1. I have another measure created to count the number of distinct values in column 1 with filters. I have a 3rd and final measure created to count the number of distinct values of column 1 with different filters. The issue I am running into is the count of measure 2 + measure 3 should equal measure 1 however added together they are GREATER than the value of measure 1 which is just a grand total. How is this possible? Unfortunately I can't share the table but below is the code I am using for the two measures:
Measure1=distinctcount('Table1'[Column1])
Measure2=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 1,'Table1'[CTest2] = "07")
Measure3=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 2,'Table1'[CTest2] = "07")
I am at a loss. Thank you in advance!!
For troubleshooting you should identify values of Column1 with Measure2 and Measure3 > 0, those are being added twice.

Power BI count rows with same ID

I'm trying to count my rows but I've got a little issue. some rows have the same ID and I don't want to count those again, it's like each row represents a product but some products have the same ID. I'm trying to count the products from Their ids.
is there any measure to apply?
I've used the measure "Countrows" but as I said I've got a lot of Duplicated IDS .
You can use DISTINCTCOUNT:
MyMeasure = DISTINCTCOUNT ( MyTable[ProductID] )

How do I manipulate measure values based on 2 other dimension tables

Power BI newbie here and I'm trying to figure how to craft my DAX to manipulate my measure values based on certain criteria in the other two tables.
Currently I have 2 separate tables which are joined by a One to Many relationship and a separate Measures table. (Total Sales Price is computed as sum of Sales Price)
My aim is to create a new measure where Total Sales Price is multiplied by 1.5x when DIM_Product_Type[Product Category] = "High".
New Measure =
CALCULATE (
SUM ( FACT_PriceDetails[Sales Price] ),
FILTER ( DIM_Product_Type, DIM_Product_Type[Product Category] = "High" )
) * 1.5
However this returns no values in my visual and I'm trying to discern if its a matter of the table joins or the DAX expressions.
Thank you for your time!
Your measure seems good.
It will select only those products with a Product Category of "High" and multiply them by 1.5 to give you result. i.e. Give me the sum of all "High" Product category Price details multiplied by 1.5.
What you need to check is:
Product Serial Numbers match across the two tables
Your Product Category does indeed contain the category "High"
You have entries in FACT_PriceDetails that link to a DIM_Product_Type that has a category of "High"
Check you have not set any filters that could be hijacking your results (e.g. excluding the "High" product category product type or the realated fact/s)
Option-1
You can do some Transformation in Power Query Editor to create a new column new sales price with applying conditions as stated below-
First, Merge you Dim and Fact table and bring the Product Category value to your Fact table as below-
You have Product Category value in each row after expanding the Table after merge. Now create a custom column as shown below-
Finally, you can go to your report and create your Total Sales measure using the new column new sales price
Option-2
You can also archive the same using DAX as stated below-
First, create a Custom Column as below-
sales amount new =
if(
RELATED(dim_product_type[product category]) = "High",
fact_pricedetails[sales price] * 1.5,
fact_pricedetails[sales price]
)
Now create your Total Sales Amount measure as below-
total_sales_amount = SUM(fact_pricedetails[sales amount new])
For both above case, you will get the same output.

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!