Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a measure that says if a day has actual sales, then show the average of sales, otherwise show "1": "
Thanks!
@ShNBl84 - If I understand correctly, you want to get the sales for each day, and then take the average of those values. Please note that is different from taking the average value of the entire set. The total is currently doing the latter, as it is simply the same calculation without the filter on day.
To average for each day, and then average the daily value, you can do something like this:
pred = var _sum = SUMMARIZE( Sheet1, [DayOfWeek], "Avg",IF( SUM(Sheet1[Sales])>0, AVERAGE(Sheet1[Sales]), 1 ) ) return AVERAGEX(_sum,[Avg])
Thanks for the time and the new techniques to study. The formula works for items with actual sales, but when I put in my measure instead of "1", I only get blanks. I am not getting blanks in my current format, but the column total is ignoring the values. 😕
what is the measure?
I haven't really looked in detail at what the problem might be but, based in @Anonymous's solution, try this variant:
pred = VAR _sum = ADDCOLUMNS ( SUMMARIZE ( Sheet1, [DayOfWeek] ), "Avg", IF ( SUM ( Sheet1[Sales] ) > 0, AVERAGE ( Sheet1[Sales] ), 1 ) ) RETURN AVERAGEX ( _sum, [Avg] )
where we use ADDCOLUMNS rather than summarize to create "Avg". SUMMARIZE introduces both row and filter contexts (and other behind-the-scenes behavior) that might give rise to issues in cases like this. ADDCOLUMNS has only a row context. No idea if it will work but it's worth a quick try.
@ShNBl84 -
I noticed you have 2 different tables. Try the following, which summarizes based off of the dimension table, instead of the fact table:
pred =
var _sum = SUMMARIZE(
DayOfWeek,
[DayOfWeek],
"Avg",IF(
SUM(DailyIndices[Sales])>0,
AVERAGE(DailyIndices[Sales]),
1
)
)
return AVERAGEX(_sum,[Avg])
Another possible additional change is to replace all instances of filtering on the fact table with a filter on the dimension table. For example, replace this:
VAR Tues = CALCULATE(AVERAGE(DailyIndices[Value]), ALL(DayOfWeek), DailyIndices[Day]="Tuesday")
with this:
VAR Tues = CALCULATE(AVERAGE(DailyIndices[Value]), ALL(DayOfWeek), DayOfWeek[Day]="Tuesday")
I appreciate the efforts. I simply keep getting blanks in the predictive cells. To get the subtotal data, I resorted to making a separate table with a new measure that calculated the total.
Hi ShNBl84, would it be possible for you to post a PBIX file that contains a bit of sample data to play with? It's much easier to help troubleshoot with some data (even if "dummy" data)
I feel like there are two things going on:
1) Strongly feel you need to use SUMX or AverageX to iterate over days
2) Not sure why you are building a measure with hard coded monday, tuesday, etc. in it. If the measure is built properly it should take that into account if you display it by day of the week
Unfortunately only have limited time to help, much better spent if you could upload a bit of sample data and show what the results are you're looking for.
Thx,
Scott
Oh, I see, you seem to be doing a Week to date type calculation I think. Definitely would be better to not hard code specific days into the formula.
Thx,
Scott
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |