Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

WEEK CALCULATIONS

Hi,

 

I have a table like below,

 

DateNetwork NameOffice NameCount
7-JunN1OFF 14
7-JunN2OFF 33
6-JunN1OFF 25
6-JunN2OFF 45
5-JunN1OFF 12
5-JunN2OFF 33
4-JunN1OFF 21
4-JunN2OFF 41
3-JunN1OFF 14
3-JunN2OFF 31
2-JunN1OFF 24
2-JunN2OFF 42
1-JunN1OFF 13
1-JunN2OFF 35
31-MayN1OFF 21
31-MayN2OFF 42
30-MayN1OFF 15
30-MayN2OFF 32
29-MayN1OFF 22
29-MayN2OFF 42
28-MayN1OFF 13
28-MayN2OFF 32

 

I have written few calculated columns,

 

Week Start date = 'Table'[Date]+-1*WEEKDAY('Table'[Date],2)+1
Week End date = 'Table'[Date]+ 7-1*WEEKDAY('Table'[Date],2)
Week Number = WEEKNUM('Table'[Date],2)
Year = YEAR('Table'[Date])
Week = if('Table'[Week Number]<10,'Table'[Year]*10 & 'Table'[Week Number],'Table'[Year]&'Table'[Week Number])
Week Rank = RANKX(all('Table'),'Table'[Week Start date],,ASC,Dense)
 
picture for reference,
dharanisrees_0-1686195047021.png

 

I want to calculate the sum of the count column for current week and for previous week for each network and office,

So i wrote the daxes,

WTD_Sum = CALCULATE(sum('Table'[Count]), FILTER(ALL('Table'),'Table'[Week Rank]=max('Table'[Week Rank])))
prevWeek_Sum = CALCULATE(sum('Table'[Count]), FILTER(ALL('Table'),'Table'[Week Rank]=max('Table'[Week Rank])-1))
 
when i used these daxes in visualization, it didnt split according to the network name instead it showed the total count for both the networks,
 
dharanisrees_1-1686195256985.png

but the expected output needed is,

 

NETWORK NAMEWTD_SUMPREVWEEK_SUM
N11120
N21115
 
Please help me achieve this! Similarly it should work for offices as well.
 
 
Thanks,
Dharani
4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table and show write those calculated column formulas in the Calendar Table.  Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Mahesh0016
Super User
Super User

Hello @Anonymous  everythings is ohk in your logic but only change is you should use WEEKNUM instead of rank.
for E.g
Create Column :

WeekNum = WEEKNUM('Table week'[Date],2)
Use in your calculation :
WTD_Sum =
CALCULATE (
    SUM ( 'Table week'[Count] ),
    FILTER (
        ALL ( 'Table week' ),
        'Table week'[WeekNum] = MAX ( 'Table week'[WeekNum] )
    )
)

############################

prevWeek_Sum =
CALCULATE (
    SUM ( 'Table week'[Count] ),
    FILTER (
        ALL ( 'Table week' ),
        'Table week'[WeekNum]
            = MAX ( 'Table week'[WeekNum] ) - 1
    )
)
Mahesh0016_1-1686204625783.png
Mahesh0016_0-1686204426533.png

@Anonymous I hope this helps you!THANK YOU!!

Anonymous
Not applicable

Hi Mahesh, Still the output is same. its gives the same old output. It is not spliting according to the network

@Anonymous I hope this helps you!THANK YOU!!
Create Column :
WTD_Sum =
CALCULATE (
SUM ( 'Table week'[Count] ),
ALLEXCEPT ( 'Table week', 'Table week'[Network Name], 'Table week'[WeekNum] ),
'Table week'[WeekNum] = MAX ( 'Table week'[WeekNum] )
)
###################################################
prevWeek_Sum =
CALCULATE (
SUM ( 'Table week'[Count] ),
ALLEXCEPT ( 'Table week', 'Table week'[Network Name] ),
'Table week'[WeekNum]
= MAX ( 'Table week'[WeekNum] ) - 1
)
**********************************************************************

Create Measure :
WTD_Sum =
CALCULATE (
    SUM ( 'Table week'[Count] ),
    FILTER (
        'Table week' ,
        'Table week'[WeekNum] = MAX ( 'Table week'[WeekNum] )
    )
)

############################

prevWeek_Sum =
CALCULATE (
    SUM ( 'Table week'[Count] ),
    FILTER (
        'Table week' ,
        'Table week'[WeekNum]
            = MAX ( 'Table week'[WeekNum] ) - 1
    )
)


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.