Forum Discussion
Power BI Modeling Question – Dynamic Common Sample + Buckets + Weighted KPIs
- 3 months ago
I think you need to use a calculation group so that you can work out the list of valid companies and then use that as a filter on your chosen measure.
Create a calculation item like
Company is in common sample = VAR _Years = TREATAS ( VALUES ( 'Sample Years'[Year] ), 'Date'[Year] ) VAR _NumYears = COUNTROWS ( _Years ) VAR _CompaniesYearsAndNumbers = CALCULATETABLE ( SUMMARIZECOLUMNS ( Company[Company ID], 'Date'[Year], "@Net sales", [Net sales], "@ebitda", [EBITDA], "@total assets", [Total assets] ), REMOVEFILTERS (), _Years ) VAR _CompaniesYears = FILTER ( _CompaniesYearsAndNumbers, [@Net sales] <> 0 && [@ebitda] <> 0 && [@total assets] <> 0 ) VAR _CompaniesAndNumYears = GROUPBY ( _CompaniesYears, Company[Company ID], "@num years", SUMX ( CURRENTGROUP (), 1 ) ) VAR _ValidCompanies = SELECTCOLUMNS ( FILTER ( _CompaniesAndNumYears, [@num years] = _NumYears ), Company[Company ID] ) VAR Result = CALCULATE ( SELECTEDMEASURE (), KEEPFILTERS ( _ValidCompanies ) ) RETURN Resultand then apply that as a filter to the visuals you want to be affected by your common sample filters.
The algorithm is relatively straitforward. First you need to calculate the qualifying measures for each company for each year selected. You can then filter out those rows where the qualifying measures are not all non-zero, and count the number of remaining years for each company.
You only want the companies where the number of valid years matches the number of years selected by the user, and you can use that list of valid companies as an additional filter on top of any other existing filters to calculate the underlying measure.
- 3 months ago
Hi,
I'm attaching a test.pbix, pls check if this is what you are looking for. https://drive.google.com/file/d/141G2onZUkz8eInk4OPWa_sbB0Uc_96Iz/view?usp=drivesdk
Hi atziovara
why did you unpivot the original table?
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
- atziovara3 months agoHelper I
FBergamaschi Thank you very much for your reply! I thought that it would be a more efficient solution, as one tutor had suggested to me that in general unpivoting tables is a good way of working with data of companies. What would you suggest?