Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Hi Team,
Hope all are doing well!
I have my sales data with multiple dimensions available but need your help in solving below case:
I need to calculate max sales amount in a week then show the average at month level.E>g
Date Sales
1/1/2022 200
1/2/2022 400
1/8/2022 600
1/10/2022 800
1/21/2022 500
Week 1 Max sale is 400
Week 2 Max Sale is 800
Week 4 Max sale is 500
Output should be
Jan22 -(400+800+500)/3=566,66
Please help @tamerj1 @FreemanZ @amitchandak @Jihwan_Kim @daXtreme @johnt75 @Anonymous @v-kkf-msft
Solved! Go to Solution.
@Anonymous
This is the best I can do. Not sure if it satisfies your rquirement. Please refer to attached sample file.
Sales Amount =
VAR CurrentWeekUm = [Week Number]
VAR T1 =
GROUPBY (
ADDCOLUMNS ( ALL ( 'Table' ), "@Week", WEEKNUM ( 'Table'[Date], 12 ) ),
[@Week],
"@Sales", MAXX ( CURRENTGROUP(), [Sales] )
)
VAR Amount = SUM ( 'Table'[Sales] )
VAR Result1 =
AVERAGEX (
FILTER ( T1, [@Week] = CurrentWeekUm ),
[@Sales]
)
VAR Result2 =
AVERAGEX ( T1, [@Sales] )
RETURN
IF (
NOT ISEMPTY ( 'Table' ),
IF (
HASONEVALUE ( 'Table'[Date] ),
IF ( Amount = Result1, Result1 ),
Result2
)
)
Hi @tamerj1 ,
Thank you for promt response. I am connecting through direct query so we dont have any weekNo column. How to fetch weekNo as measure and then rewrite this query?
because Values function expecting a column value not measure.
@Anonymous
You have to have the column. If you don't the it has to be created from the source. Not sure if a locally imported/created Date table can be connected to your Sales table but it is worth it to try (of course if you are allowed to create relationships)
Thank you for the suggestion @tamerj1 . Since its a direct query connection then relationship tab is not available.
I dont think backend team would add a column 😞
I am able to get weekNo in a measure using (WeeNum=WeeKNUM(Max(Table[Date]))
Is ther any way to pass this to get desired output?
Max sale at each week and monthy average of maximum data?
@Anonymous
It doesn't have to be connected table but can you even create a local table or locally import one?
Hi @tamerj1 Since its a direct query(SAP-HANA) so adding a local table or any other data source is disable on the Power BI desktop.
@Anonymous
This is the best I can do. Not sure if it satisfies your rquirement. Please refer to attached sample file.
Sales Amount =
VAR CurrentWeekUm = [Week Number]
VAR T1 =
GROUPBY (
ADDCOLUMNS ( ALL ( 'Table' ), "@Week", WEEKNUM ( 'Table'[Date], 12 ) ),
[@Week],
"@Sales", MAXX ( CURRENTGROUP(), [Sales] )
)
VAR Amount = SUM ( 'Table'[Sales] )
VAR Result1 =
AVERAGEX (
FILTER ( T1, [@Week] = CurrentWeekUm ),
[@Sales]
)
VAR Result2 =
AVERAGEX ( T1, [@Sales] )
RETURN
IF (
NOT ISEMPTY ( 'Table' ),
IF (
HASONEVALUE ( 'Table'[Date] ),
IF ( Amount = Result1, Result1 ),
Result2
)
)
Hi @Anonymous
1) you would need to create a WeekNum column with this:
dataset:
Hi @FreemanZ
Thank you for promt response. I am connecting through direct query so we dont have any weekNo column. How to fetch weekNo as measure and then rewrite this query?
because Values function expecting a column value not measure.
Hi @Anonymous
Please try
Sales Amount =
AVERAGEX (
VALUES ( 'Date'[Week] ),
CALCULATE (
MAXX ( VALUES ( 'Date'[Date] ), CALCULATE ( SUM ( Sales[Sales] ) ) )
)
)
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Ask questions in Eventhouse and KQL, Eventstream, and Reflex.
User | Count |
---|---|
71 | |
37 | |
21 | |
18 | |
15 |
User | Count |
---|---|
126 | |
32 | |
27 | |
24 | |
23 |