Forum Discussion
chuongnq
1 year agoRegular Visitor
Power BI: Calculating Product_Code and Days Matching Max Date by Type and Group
Problem Statement: I have a dataset A with the following columns: Date: Date of the record. Product_Code: Product code. Type: Product type (e.g., X, Y). Group: Product group (e.g., M, N). ...
- 1 year ago
hi
1) Use the following DAX formula to create a calculated table:IntermediateTable = SUMMARIZE( FILTER( 'Dataset A', 'Dataset A'[Date] IN VALUES('DateTable'[Date]) ), 'Dataset A'[Type], 'Dataset A'[Group], "Max_Date_By_Type_Group", MAX('Dataset A'[Date]), "Product_Code", FIRSTNONBLANK( FILTER( 'Dataset A', 'Dataset A'[Date] = MAX('Dataset A'[Date]) ), 'Dataset A'[Product_Code] ) )2) Use this DAX measure to calculate the count of days matching Max_Date_By_Type_Group:
Amount_Date = CALCULATE( COUNTROWS('Dataset A'), 'Dataset A'[Date] IN DISTINCT(IntermediateTable[Max_Date_By_Type_Group]), 'Dataset A'[Product_Code] IN DISTINCT(IntermediateTable[Product_Code]) )Visualize:
- Add Product_Code and Amount_Date to a table visual.
- The slicer on Date will dynamically filter results.
This ensures the correct Product_Code and Amount_Date based on the slicer selection.
rohit1991
1 year agoSuper User
hi
1) Use the following DAX formula to create a calculated table:
IntermediateTable =
SUMMARIZE(
FILTER(
'Dataset A',
'Dataset A'[Date] IN VALUES('DateTable'[Date])
),
'Dataset A'[Type],
'Dataset A'[Group],
"Max_Date_By_Type_Group", MAX('Dataset A'[Date]),
"Product_Code",
FIRSTNONBLANK(
FILTER(
'Dataset A',
'Dataset A'[Date] = MAX('Dataset A'[Date])
),
'Dataset A'[Product_Code]
)
)
2) Use this DAX measure to calculate the count of days matching Max_Date_By_Type_Group:
Amount_Date =
CALCULATE(
COUNTROWS('Dataset A'),
'Dataset A'[Date] IN DISTINCT(IntermediateTable[Max_Date_By_Type_Group]),
'Dataset A'[Product_Code] IN DISTINCT(IntermediateTable[Product_Code])
)Visualize:
- Add Product_Code and Amount_Date to a table visual.
- The slicer on Date will dynamically filter results.
This ensures the correct Product_Code and Amount_Date based on the slicer selection.