Forum Discussion
DAX equivalent to complex SQL query
- 9 years ago
Hi there,
Please try adding the following three calcuated tables:
ReportAttributeCount = SELECTCOLUMNS( SUMMARIZECOLUMNS( 'Table2'[ReportName], "ReportA_AttributeCount" , COUNTROWS('Table2') ), "ReportA",[ReportName], "ReportA_AttributeCount",[ReportA_AttributeCount] )CommonAttributesCount = SUMMARIZE( FILTER( GENERATE( SELECTCOLUMNS( Table2, "ReportName",'Table2'[ReportName], "AttributeName",'Table2'[AttributeName] ) , SELECTCOLUMNS( Table2, "ReportName2",'Table2'[ReportName], "AttributeName2",'Table2'[AttributeName] ) ),[AttributeName]=[AttributeName2] && [ReportName]< [ReportName2] ), [ReportName], [ReportName2], [AttributeName] )and finally
ReportTable = VAR CommonAttributesCount2 = SELECTCOLUMNS( SUMMARIZE( 'CommonAttributesCount', [ReportName], [ReportName2], "CommonAttributeCount",DISTINCTCOUNT('CommonAttributesCount'[AttributeName])),"CACA.ReportA",[ReportName],"CACA.ReportB",[ReportName2],"CACA.DC",[CommonAttributeCount]) VAR FINAL = ADDCOLUMNS( FILTER( CROSSJOIN( FILTER( CROSSJOIN( SELECTCOLUMNS( ReportAttributeCount, "RAC.ReportA",[ReportA], "RAC.ReportA_AttributeCount", [ReportA_AttributeCount] ), CommonAttributesCount2), [RAC.ReportA]=[CACA.ReportA] ), SELECTCOLUMNS( 'ReportAttributeCount', "RACB.ReportA",[ReportA], "RACB.ReportA_AttributeCount",[ReportA_AttributeCount] ) ),[CACA.ReportB]=[RACB.ReportA]) , "reportApercentage",DIVIDE([CACA.DC],[RAC.ReportA_AttributeCount]), "reportBpercentage",DIVIDE([CACA.DC],[RACB.ReportA_AttributeCount])) RETURN FINALwhich for me returns this as a result
Hi hxkresl
Just a couple of questions that will help me. So I understand the code is ok for the small sample dataset, yes? :)
Any chance you can give me a slightly bigger dataset including some duplication that you want to ignore. It would be great if you can do this and also provide the expected result for the bigger dataset to help me pick the best place to apply the de-dup.
Cheers,
Phil
- BalaVenuGopal8 years agoResolver I
Hi Phil_Seamark ,
I had heavy code writen in the stored procs to get the data which involves lot of temp table joins and where conditions .(Currently this proc is inserting data into sql table from there SSRS repor is rendering)
If i want to convert this SSRS to powerBi report which one would be faster DAX or get data from stored proc as source
Which once would be technically best suits .
Could you plese suggest.