Forum Discussion
How to populate missing rows dynamically for calculations?
I'm trying to create a table in Power BI that, at its core, displayed the frequency with which certain items are purchased. This data is being pulled from MS SQL and looks something like this:
From there, various calculations will be applied to each row. My trouble is that those calculations (measures) still need to run on the rows where the frequency of a given quantity was 0. Thus, what I figure I'm needing to do is add rows with a frequency of 0 for all quantities from 1 to the max value for each item.
My immediate thought is that this is much like completing a table with dates by joining to a date table. While I suspect this is the right approach, I'm running into 2 issues:
- The max frequency is not consistent. For some widgets it might be 7. For others it might be 5,000. So I generate a quantity table with a max of 5,000. Thus, when creating a table of values to join on and telling PBI to show items with no data, it displays 5,000 rows. I need it to truncate at the max value for the widget selected.
- It doesn't actually perform calculations. Even though it shows the rows, there's no data in them to calculate with.
So is there any way I can get the filtered table to include the omitted rows up to the max and populate it with 0's so the calculations will run?
Hi JonV
You may try below measure:
Measure 2 = VAR a = MAXX ( ALLSELECTED ( Table1 ), Table1[Quantity] ) RETURN IF ( MAX ( 'Table'[Quantity] ) <= a, CALCULATE ( SUM ( Table1[Frequency] ) ) + 0 )Regards,
Cherie
7 Replies
- v-cherch-msftMicrosoft Employee
Hi JonV
It seems you may create a measure like below. Attached the sample file. If it is not your case,please share the sample data and expected output.
How to Get Your Question Answered Quickly
Measure = CALCULATE(SUM(Table1[Frequency]))+0
Regards,
Cherie
- JonVHelper IIThanks Cherie. That solves one problem. However, I still have the problem of needing the quantity list to truncate at the max value of the frequency. Otherwise, when I convert things to a chart, the data for items that only have a few lower values will be scrunched up at one side.
- v-cherch-msftMicrosoft Employee
Hi JonV
I cannot fully understand it. Could you provide the simplified data and expected output for us?
How to Get Your Question Answered Quickly
Regards,
Cherie