Forum Discussion
Performance Issue with COUNTROWS Summarize
gardas_swathi Try this:
Product Coverage :=
VAR DemandProductIDColumn =
VALUES ( 'Demand Table'[Product ID] )
VAR NewColumns =
ADDCOLUMNS (
DemandProductIDColumn,
"@Demand", [Demand],
"@MonthlySupply", [MonthlySupply],
"@NetAvailSupplyDemand", [NetAvailSupplyDemand]
)
VAR FilterRows =
FILTER (
NewColumns,
VAR Demand_True_LessThanZero =
ISBLANK ( [@Demand] ) = TRUE
|| [@Demand] <= 0
VAR MonthlySupply_True_LessThanZero =
ISBLANK ( [@MonthlySupply] ) = TRUE
|| [@MonthlySupply] <= 0
VAR NetAvailSupplyDemand_True_LessThanZero =
ISBLANK ( [@NetAvailSupplyDemand] ) = TRUE
|| [@NetAvailSupplyDemand] <= 0
VAR Demand_FalseNotZero =
ISBLANK ( [Demand] ) = FALSE
|| [Demand] > 0
VAR MonthlySupply_True_Zero =
ISBLANK ( [@MonthlySupply] ) = TRUE
|| [@MonthlySupply] = 0
VAR Result =
IF (
OR (
Demand_True_LessThanZero && MonthlySupply_True_LessThanZero
&& NetAvailSupplyDemand_True_LessThanZero,
Demand_True_LessThanZero
&& [@MonthlySupply] > 0
),
-1,
IF (
Demand_FalseNotZero && MonthlySupply_True_Zero,
-1,
[@NetAvailSupplyDemand]
)
)
RETURN
Result > 0
)
VAR RowCount =
COUNTROWS ( FilterRows )
VAR Result =
IF ( ISBLANK ( RowCount ) = TRUE && [NetAvailSupplyDemand] <= 0, 0, RowCount )
RETURN
ResultHi AntrikshSharma ,
I tried to execute VAR New Columns to see the data. I observed that MonthlySupply and NetAvailSupplyDemand are not slicable by productID. Screenshot for reference. I have changed the measure names in my original post to make it simple. Below screenshot the measure names . All these tables are related to Product Table. Monthly Supply is all same for all the product ID's . Net Avail Formula is MonthlySupply-Demand, so Net Avail values seem to change a bit . But overall values in below table are incorrect. I need to get Demand, Monthly Supply and Net Avail by Product ID and then do all the checks
- AntrikshSharma3 years agoCommunity Champion
gardas_swathi Can you share the screenshot of the diagram view, use VALUES ( Product'[ID] ) from product table as I forgot there are multiple facts. So VALUES ( Demand[ProductID] ) won't transfer the filter from context transition to other tables that aren't related to Demand Table.