Forum Discussion
logical error in dynamic filtering for calculated tables using summarize
Hi All
I have created a measure using summarize which dynamically calculates a list for last year and this works fine for all the filters. Still, i am unable to filter it dynamically using the column u have created the filter for(Append1[CustomerList_Filtered]).
if i insert Append1[CustomerList_Filtered] in the Allexcept condition i am getting an error "The column 'CustomerList_Filtered' specified in the 'SUMMARIZE' function was not found in the input table."
- Anonymous1 year ago
HI Anonymous
Apologies for the late reply , but i have magaed to resolve it myself.
The issue with the code was regardig data lineage calculated columns.
work around was to created indipendant calculated coumns for the selections.
Please find the updated code below .var Start_Date = FIRSTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] )var start_Date_LY = DATEADD( Start_Date , -1 , YEAR)var End_Date = LASTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] )var End_Date_LY = DATEADD( End_Date , -1 , YEAR)var Selected_Segment = SELECTEDVALUE( 'Customer Segmentation'[ID] , 0 )VAR My_table =SUMMARIZE ( Append1 ,Append1[CustomerList_Filtered],"Accepted Jobs2", [Accepted Jobs.AG],"Accepted Revenue2", [Accepted Sales.AG])VAR final_IC = FILTER ( My_table, [Accepted Jobs2] = 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MSC = FILTER ( My_table, [Accepted Jobs2] > 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MC =FILTER ( My_table, [Accepted Revenue2] > 3000 && [Accepted Revenue2] <= 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_KC = FILTER ( My_table, [Accepted Revenue2] > 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )returnIF( Selected_Segment = 1 , SUMX( final_IC , [Accepted Revenue2]) ,IF( Selected_Segment = 2 , SUMX( final_MSC , [Accepted Revenue2]) ,IF( Selected_Segment = 3 , SUMX( final_MC , [Accepted Revenue2]) ,IF( Selected_Segment = 4 , SUMX( final_KC , [Accepted Revenue2]) ,IF( Selected_Segment = 5 , SUMX( final_MSC , [Accepted Revenue2])+SUMX( final_MC , [Accepted Revenue2])+SUMX( final_KC , [Accepted Revenue2]) ,SUMX( My_table , [Accepted Revenue2] ) )))))
FYI everything is based on only one fact table and there is no join between the fact table(Append1) and the refrence table(Customer Segmentation).
11 Replies
- Dangar332Resident Rockstar
Hi ,Anonymous
Since the measure accept a scalar value and the above code you have provided returns a table, the code you supplied above is unacceptable in the measure. Could you please supply the entire measure code?- AnonymousNot applicable
Hi Dangar332
please find below the full codevar Start_Date = DATEADD( FIRSTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] ) , -1 , YEAR)var start_Date_LY = DATEADD( Start_Date , -1 , YEAR)var End_Date = DATEADD( LASTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] ) , -1, YEAR)var End_Date_LY = DATEADD( End_Date , -1 , YEAR)var Selected_Segment = SELECTEDVALUE( 'Customer Segmentation'[ID] , 0 )VAR My_table =SUMMARIZE (FILTER (ALLEXCEPT( Append1 ,Append1[Service Centre Name],Append1[Channel V1] ,Append1[NSO] ,Append1[Month No] ,Append1[CustomerOrganisation]) ,Append1[StatusDateTime] >= Start_Date &&Append1[StatusDateTime] <= End_Date),Append1[CustomerList_Filtered],"Accepted Jobs2", [Accepted Jobs.AG],"Accepted Revenue2", [Accepted Sales.AG])VAR final_IC = FILTER ( My_table , [Accepted Jobs2] = 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MSC = FILTER ( My_table, [Accepted Jobs2] > 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MC =FILTER ( My_table, [Accepted Revenue2] > 3000 && [Accepted Revenue2] <= 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_KC = FILTER ( My_table, [Accepted Revenue2] > 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )returnIF( Selected_Segment = 1 , SUMX( final_IC , [Accepted Revenue2]) ,IF( Selected_Segment = 2 , SUMX( final_MSC , [Accepted Revenue2]) ,IF( Selected_Segment = 3 , SUMX( final_MC , [Accepted Revenue2]) ,IF( Selected_Segment = 4 , SUMX( final_KC , [Accepted Revenue2]) ,IF( Selected_Segment = 5 , SUMX( final_MSC , [Accepted Revenue2])+SUMX( final_MC , [Accepted Revenue2])+SUMX( final_KC , [Accepted Revenue2]) ,SUMX( My_table , [Accepted Revenue2] ) )))))
- AnonymousNot applicable
Hi Anonymous,
Thank you for reaching out on the Microsoft Fabric Community Forum!
I’ve created a PBIX file using some sample data and executed the code you mentioned. It worked fine on my end. Please find the attached PBIX file for your reference.Let me know if you need further assistance!
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thank you.
- AnonymousNot applicable
Hi Anonymous
Thank you for your patience.please let us know if anything was helpful to you, so that we can convert it into a formal answer. If so, we would appreciate it if you could Accept it as a solution and drop a 'Kudos' so other members can find it more easily.
Thank you. - AnonymousNot applicable
Hi Anonymous
We haven’t heard back since our last response and wanted to check if your query has been resolved. If not, please feel free to reach out for further assistance. If it has been resolved, kindly mark the helpful reply as the solution to make it easier for others to find. A kudos would also be greatly appreciated!
Thank you. - AnonymousNot applicable
Hi Anonymous
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.- AnonymousNot applicable
Hi
Thank you for the reply, but I am trying to generate a dynamic virtual table that will react to the filters.
- AnonymousNot applicable
Hi Anonymous
Could you please confirm whether this data is connected to a live query or if it is connected to import mode/Excel?- AnonymousNot applicable
The data is connected from SQL server and not a direct query.
- AnonymousNot applicable
Hi Anonymous
can you please provide sample data?
Thank you- AnonymousNot applicable
HI Anonymous
Apologies for the late reply , but i have magaed to resolve it myself.
The issue with the code was regardig data lineage calculated columns.
work around was to created indipendant calculated coumns for the selections.
Please find the updated code below .var Start_Date = FIRSTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] )var start_Date_LY = DATEADD( Start_Date , -1 , YEAR)var End_Date = LASTNONBLANK( 'Trading Days'[Date] , 'Trading Days'[Date] )var End_Date_LY = DATEADD( End_Date , -1 , YEAR)var Selected_Segment = SELECTEDVALUE( 'Customer Segmentation'[ID] , 0 )VAR My_table =SUMMARIZE ( Append1 ,Append1[CustomerList_Filtered],"Accepted Jobs2", [Accepted Jobs.AG],"Accepted Revenue2", [Accepted Sales.AG])VAR final_IC = FILTER ( My_table, [Accepted Jobs2] = 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MSC = FILTER ( My_table, [Accepted Jobs2] > 1 && [Accepted Revenue2] <= 3000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_MC =FILTER ( My_table, [Accepted Revenue2] > 3000 && [Accepted Revenue2] <= 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )VAR final_KC = FILTER ( My_table, [Accepted Revenue2] > 12000 && Append1[CustomerList_Filtered] <> "NO NAME" )returnIF( Selected_Segment = 1 , SUMX( final_IC , [Accepted Revenue2]) ,IF( Selected_Segment = 2 , SUMX( final_MSC , [Accepted Revenue2]) ,IF( Selected_Segment = 3 , SUMX( final_MC , [Accepted Revenue2]) ,IF( Selected_Segment = 4 , SUMX( final_KC , [Accepted Revenue2]) ,IF( Selected_Segment = 5 , SUMX( final_MSC , [Accepted Revenue2])+SUMX( final_MC , [Accepted Revenue2])+SUMX( final_KC , [Accepted Revenue2]) ,SUMX( My_table , [Accepted Revenue2] ) )))))
FYI everything is based on only one fact table and there is no join between the fact table(Append1) and the refrence table(Customer Segmentation).