Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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] ) ) )
)
)
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |