I am looking for a solution of this probably simple problem. I have two tables in Power BI: Inventory and Sales:
Inventory Sales
Item Title Item Quantity
123 Soap 124 5
124 Detergent 123 8
125 Toothpaste
126 Tooth brush
How can I make a table that lists items not sold. I.e. I need to return:
Item Title
125 Toothpaste
126 Tooth brush
I would add a Measure to the Inventory table, e.g.
Item Quantity = 0 + SUM ( Sales[Quantity] )
Then I would add that Measure to the Visual level filters for your table visual, and set the filter to:
Show items when the value:
is
0
You could create a calculated column:
=IF(LOOKUPVALUE(Sales[item];Sales[item];Inventory[item]);BLANK();1)
and then filter for this column = 1
Or you could do this:
=IF(LOOKUPVALUE(Sales[item];Sales[item];Inventory[item]);BLANK();[title])
If you use this columns on your axis in a visual/table, only items not sold will show up.
Or you could use create a measure like this, assuming there is a relationship between the two tables on Item:
Products not being sold :=
IF (
ISBLANK (
CALCULATE (
DISTINCTCOUNT ( Inventory[item] );
FILTER ( Sales; Sales[item] = [item] )
)
);
1;
BLANK ()
)
if you add this measure to your visual/table only items not sold will show up
Related
I am new to Power BI and learning how to perform cohort analysis with DAX in Power BI. Is there any way to find out how many times (or if easier if a customer buys more than a certain threshold) their first month?
If I have the table Customers:
ID | DateOfFirstRegistration
And the table of orders:
ID | customerId | orderDate
Let me know if any more information is helpful!
EDIT: If possible, is it also possible to plot it in a matrix with customers in each row and month 1 through 3 in the columns?
Thank you
You can do something like this measure in a table visualization together with customer ID:
First Month Purchases =
VAR _registration =
SELECTEDVALUE ( 'customers'[DateOfFirstRegistration] )
RETURN
CALCULATE (
COUNTROWS ( 'orders' ) ,
DATESINPERIOD (
'orders'[orderDate] ,
_registration ,
1 ,
MONTH
)
)
I have two data bases.One contain carder and other one contain data.What I want is once I select the designation from the slicer.Then select the the employee and need to show higher defect rate styles.I have set little slicer to select higher 1 ,2 ,3 defect rate styles. .My measures as below.
Total Check = SUM(Records[Check Qty])
Total Defects = SUM(Records[Defects])
Selected_Top_N = SELECTEDVALUE('Top N'[Column1])
Defect pct = CALCULATE((DIVIDE([Total Defects],[Total Check])),TOPN([Selected_Top_N],ALL(Records[Style]),DIVIDE([Total Defects],[Total Check]),DESC),VALUES(Records[Style]))
This "Defect pct" measure works fine for Executive grade. Because it has active relationship. For qc it shows blank. My question is how to modify "Defect pct" measure using "userrelationship" or any other dax function to see top styles once I clicked qc from designation slicer and qc from the employee list.Without unpivoting I can get check qty and defect qty like below with %.by selected value for designation.'code'
Selected_designation = SELECTEDVALUE(Carder[Desingation])
SWITCH(true(),[selected_designation] ="Executive",DIVIDE([Total Defects],[Total Check]),
[selected_designation] ="QC",CALCULATE(DIVIDE([Total Defects],[Total Check]),USERELATIONSHIP(Records[QC],Carder[EMPLOYEE])))
'then using switch function I get these with two calulations.one for the direct relation ship.and other calculation with userrelationship for inactive one.I want rank this % with topN.End result must be once I click excetive I want rank higher defect % pct according to the selected executive and once I click qc I want the same.
You need first to convert your fact table into this shape using unpivoting the last 2 columns.
Like This:
Then Create a designation Table consisting of 2 columns:
Like This:
Your Final Model View should appear like this:
(Updated) DAX Code For Defect pct:
Defect pct =
VAR selection =
SELECTEDVALUE ( Carder[Desingation] )
VAR conditional_selection =
SWITCH (
selection,
"Executive", CALCULATE ( MAXX ( Records, DIVIDE ( [Total Defects], [Total Check] ) ) ),
"QC",
CALCULATE (
MAXX ( Records, DIVIDE ( [Total Defects], [Total Check] ) ),
USERELATIONSHIP ( Records[QC], Carder[EMPLOYEE] )
)
)
RETURN
conditional_selection
I am working to get cumulative distinct count of uids on daily basis. My dataset consists dates and UserIDs active on that date. Example : Say there are 2 uids (235,2354) appeared on date 2022-01-01 and they also appeared on next day with new uid 125 (235,2354,125) on 2022-01-02 At this point i want store cumulative count to be 3 not 5 as (user id 235 and 2354 already appeared on past day ).
My Sample Data looks like as follows:
https://github.com/manish-tripathi/Datasets/blob/main/Sample%20Data.xlsx
enter image description here
and my output should look as follows:
enter image description here
Here's one way that seems to work, using your linked Excel sheet as the data source.
Create a new table:
Table 2 = DISTINCT('Table'[Date])
Add the columns:
MAU = CALCULATE(
DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] <= EARLIER('Table 2'[Date]))
DAU = CALCULATE(DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] = EARLIER('Table 2'[Date]))
Result from your Excel data
I have a table like shown below:
ID
Date
Asset
Location
145
7/29/22
A
Market
145
7/30/22
A
Warehouse
145
7/29/22
B
Market
145
7/29/22
C
Truck
150
7/30/22
B
Market
145
7/29/22
D
Market
145
7/30/22
A
Market
What I am trying to accomplish is to get a distinct count of IDs for each date with a location filter as well. So I would want a count of ID based on the slicer selected Date of 7/29/22 AND 7/30/22 for the Market Location. The desired result is 2 for the selected dates from the date slicer which directly corresponds to the date column in the table.
I was trying to use this DAX formula and wasn't getting anywhere....
IDsMarket =
CALCULATE (
DISTINCTCOUNT ( 'Products'[ID] ),
ALL ( 'Products' )
)
I have a measure dropped onto a card. I should have specified that. My apologies. I need 1 measure to show me the combined count for the two days selected.
I tried this with countrows as well but of course the result wasn't distinct... Any help would be greatly appreciated!!
The formula you're looking for is
IDsMarket =
CALCULATE(
DISTINCTCOUNT('Products'[ID]),
'Products'[Location] = "Market"
)
The resulting Table will look like this
But if you put the measure on a Card visual, you'll get
So in DAX the same measure can yield 1000 different values - depending on the filter context.
I created a conditional column in Power Query and combined the ID with the "day" number from the date column which allowed me to then do a distinct count on that combined custom column which produced to correct answer. Sorry for all the confusion. One of those days.
I have created a report for the HR department. One of the visuals aims to display the pyramid of ages of the employees by gender (we take cluster of 5 years, e.g. 20-25 for people between 20 and 25 years old).
To make it simple, data wise, I have a table with the list of employees, including their date of birth and many other fields, not relevant for this post. I added a calculated column with the age cluster based on the today’s date:
AgeCluster =
VAR AgeCalc=if(HR_DATA[Birthdate]=blank(),blank(),DATEDIFF(HR_DATA[Birthdate],today(),YEAR))
VAR Mult5=INT(AgeCalc/5)
RETURN
if(isblank(AgeCalc),blank(),5*Mult5&"-"&5*(Mult5+1))
And I have a basic visual (tornado chart with the AgeCluster in Group, showing male and female)
Now my issue is that my report should be dynamic, so the user should be able to see the situation in the past or in the future... I have a calendar table (not linked to my HR_Data table), and a date slicer on my report's page. I need the age cluster to be recalculated.
I have tried a calculated table, but I can’t get it working properly. I have read various blog posts on similar issue, but still can't figure out how to solve it...
Any idea or tips much appreciated.
Thank you so much!
Dynamic filtering usually means in these situations that you need a fixed x-axis to work with. That x-axis is calculated outside the original table, such as a parameter table.
Assuming your data looks like this:
Table: Employees
EmployeeID
DOB
1
20 March 1977
2
05 December 1981
3
25 December 1951
4
20 December 1954
5
04 March 1980
6
24 July 1968
7
07 June 1984
8
01 October 1992
9
25 February 1999
10
02 November 1987
First, we need to create the Age Groups with their respective lower and top bands. This table uses a similar code when a parameter table is created.
Table: Buckets
Because you are using whole numbers, I think is best to calculate the TopBand by adding 4. In that case, you don't have repeating numbers. In other words, ranges shouldn't overlap (20-25 and 25-30)
Buckets =
SELECTCOLUMNS (
GENERATESERIES ( 20, 80, 5 ),
"Age Series",
[Value] & " - " & [Value] + 4,
"LowerBand", [Value],
"TopBand", [Value] + 4
)
Also, we will need a Calendar Table to filter accordingly.
Table: CalendarHR
CalendarHR =
ADDCOLUMNS (
CALENDAR ( MIN ( Employees[DOB] ), TODAY () ),
"Year", YEAR ( [Date] )
)
With all that, you can create a calculation that can be filter dynamically.
DAX Measure:
EmployeesbyBracket =
VAR _SelectedDate =
MAX ( CalendarHR[Date] )
VAR _SelectedLowerBand =
SELECTEDVALUE ( Buckets[LowerBand] )
VAR _SelectedTopBand =
SELECTEDVALUE ( Buckets[TopBand] )
VAR EmployeesAge =
ADDCOLUMNS (
Employees,
"Age",
INT ( DATEDIFF ( [DOB], _SelectedDate, YEAR ) / 5 ) * 5
)
RETURN
COUNTROWS (
FILTER (
EmployeesAge,
[Age] >= _SelectedLowerBand
&& [Age] <= _SelectedTopBand
)
)
Output
I've created a table visual with the Age Groups from the Buckets table.
Both a calculated column and a calculated table will be static and not achieve your desired objective. You need age to be calculated via a measure.
Create a disconnected table with your age buckets and then implement the dynamic segmentation pattern.