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

How to differentiate completed months and non completed months in Power BI

Hi Team,

 

I have got a requirement to show line chart with data points shown below . Please help me with this. 

 

MonthVulnerabilities Week Ending
August383745
September323455
October3774

I have complete set of data (i.e full 5 weeks ) for August and September as those are previous months. However, October is still current month and current week is 4 . 

 

So, the data points for line chart should be 38374 , 32345 and 377 (until the week changes for october) .if week changes and data sums up to 3839(example) , the data points for line chart should be 38374 , 32345 and 3839 . 

 

I am unable to show most current weeks data for current month and complete data for previous months . Kindly help . 

 

As of now, I have created a Week Number based out of weekending to just display last week's data . However,its not working for me . 

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

I made one sample for your reference, please check the steps as below.

 

1. Create a Calenda table and create calculated columns in the data table. Here we should create relationship between fact table and the calenda table.

 

Calenda = CALENDARAUTO()
weekend = IF(ISBLANK([Measure]),BLANK(),CALCULATE(MAX(Calenda[weekmonth]),ALLEXCEPT(Calenda,Calenda[Month])))
weekmonth = 1+WEEKNUM(Calenda[Date])-WEEKNUM(STARTOFMONTH(Calenda[Date]))

2. To create some calculated columns in the fact table.

 

Month = FORMAT(Table1[Date],"mmmm")
week = 1+WEEKNUM(Table1[Date])-WEEKNUM(STARTOFMONTH(Table1[Date]))

3. Create the measures as below.

 

Measure = var total = CALCULATE(SUM(Table1[# Missing Patches]))
var maxweek = CALCULATE(MAX(Table1[week]),FILTER(Table1,Table1[Month]=FORMAT(TODAY(),"mmmm")))
return 
IF(MAX(Calenda[Month])=FORMAT(TODAY(),"mmmm"),CALCULATE(SUM(Table1[# Missing Patches]),FILTER(Table1,Table1[week]=maxweek)),total)
weekend = IF(ISBLANK([Measure]),BLANK(),CALCULATE(MAX(Calenda[weekmonth]),ALLEXCEPT(Calenda,Calenda[Month])))

Capture.PNG

For more details, please chekc the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

Can you post sample source data? I assume that what you presented is what you want displayed? So that I understand, if you are in a non-completed month, you want to display only the most recent week data but if a month is completed, you want the sum of all of the weeks of data for that month, correct?

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

 

You are almost there. Exactly, so when I am in a non-completed month, i am looking for most recent week data and if I am in previous months , i am looking for sum of all the weeks of data. Below is data sample . 

 

DateVPDirectorManager# AssetsCriticalHighMediumLow# Missing Patches
8/31/2018   46546456000546544564686546141171736
8/31/2018   16954152000031656165487261226663274
8/31/2018   654347164562513653546511260623102682
8/31/2018   546456956542131234653685645440958
8/31/2018   2687534568723212165032545665779596
8/31/2018   654646143358312461234566578304638
8/31/2018   8684617854652316550001651815281
9/30/2018   46546505498546544564686546141171234
9/30/2018   16954202010031656165487261226663374
9/30/2018   654357164562513653546511260623102682
9/30/2018   546456920392131234653685645437343
9/30/2018   2687534440923212165032545665778318
9/30/2018   654646143321312461234566578304601
9/30/2018   8684617854652316550001651815281
10/24/2018   46546456000546544564686546141171736
10/24/2018   16954152000031656165487261226663274
10/24/2018   654347164562513653546511260623102682
10/24/2018   546456956542131234653685645440958
10/24/2018   2687534568723212165032545665779596
10/24/2018   654646143358312461234566578304638
10/24/2018   8684617854652316550001651815281

Hi @Anonymous,

 

I made one sample for your reference, please check the steps as below.

 

1. Create a Calenda table and create calculated columns in the data table. Here we should create relationship between fact table and the calenda table.

 

Calenda = CALENDARAUTO()
weekend = IF(ISBLANK([Measure]),BLANK(),CALCULATE(MAX(Calenda[weekmonth]),ALLEXCEPT(Calenda,Calenda[Month])))
weekmonth = 1+WEEKNUM(Calenda[Date])-WEEKNUM(STARTOFMONTH(Calenda[Date]))

2. To create some calculated columns in the fact table.

 

Month = FORMAT(Table1[Date],"mmmm")
week = 1+WEEKNUM(Table1[Date])-WEEKNUM(STARTOFMONTH(Table1[Date]))

3. Create the measures as below.

 

Measure = var total = CALCULATE(SUM(Table1[# Missing Patches]))
var maxweek = CALCULATE(MAX(Table1[week]),FILTER(Table1,Table1[Month]=FORMAT(TODAY(),"mmmm")))
return 
IF(MAX(Calenda[Month])=FORMAT(TODAY(),"mmmm"),CALCULATE(SUM(Table1[# Missing Patches]),FILTER(Table1,Table1[week]=maxweek)),total)
weekend = IF(ISBLANK([Measure]),BLANK(),CALCULATE(MAX(Calenda[weekmonth]),ALLEXCEPT(Calenda,Calenda[Month])))

Capture.PNG

For more details, please chekc the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Hi Frank,

 

There is little tweak in the requirement and I tried to explain the issue below .

 

As of now, the formulaes you have created are summing up for the entire month , but I am just looking for a week . and that week should be like this. 

 

- For August , we just have one record(row) and that is 31-Aug ,we should get #Missing Vulnerabilities equal to 469,065

- For September, last week data should be summed up . which should be equal to 259,176 . (26th Aug week) 

- For October , Last week is 24th oct week and data should be summed up which is equal to 459,809 . 

 

So , ideally we are looking at just last weeks data in each month . Could you please help me in modifying those as I am new to Power BI ?

 

Dataset : 

 

 

DateVPDirectorManager # AssetsCriticalHighMediumLow# Missing vulnerabilities
31-AugVPDirectorManager78,394154,093229,00668,56316,141469,065
12-SepVPDirectorManager2,7852,2462,7871,430246,487
12-SepVPDirectorManager2,5227,82642,93933,4186,55291,997
12-SepVPDirectorManager24,00059,88455,110510115,045
12-SepVPDirectorManager27,00078,238109,95940188,201
12-SepVPDirectorManager3,6220625,3627,24432,612
12-SepVPDirectorManager4965526716,6647218,608
12-SepVPDirectorManager17,9695,34717,5341,6341,60026,115
19-SepVPDirectorManager3,08312,8363,5722,735021,097
19-SepVPDirectorManager3,0435,68318,74217,9126,80048,694
19-SepVPDirectorManager23,33432,63738,581040071,618
19-SepVPDirectorManager27,00078,238109,95940188,201
19-SepVPDirectorManager3,6220025,3687,24832,616
19-SepVPDirectorManager1,6404341,5603,7601,3017,055
19-SepVPDirectorManager20,6915,42419,0381,5331,50427,499
19-SepVPDirectorManager000000
19-SepVPDirectorManager000000
19-SepVPDirectorManager000000
19-SepVPDirectorManager000000
26-SepVPDirectorManager3,1144,5107431,795014,143
26-SepVPDirectorManager3,1086,78922,48221,3416,99757,609
26-SepVPDirectorManager23,45163,06534,103055120,674
26-SepVPDirectorManager30,045376600119
26-SepVPDirectorManager3,6220025,3687,24832,616
26-SepVPDirectorManager1,6402931,2913,3961,3266,306
26-SepVPDirectorManager20,6915,42419,0381,5331,50427,499
26-SepVPDirectorManager000000
26-SepVPDirectorManager000000
26-SepVPDirectorManager1447313610210
26-SepVPDirectorManager000000
3-OctVPDirectorManager2,9863,8376491,585113,169
3-OctVPDirectorManager3,0796,01519,91518,6985,93650,564
3-OctVPDirectorManager23,45163,06534,103055120,674
3-OctVPDirectorManager30,21341,78314,5560056,339
3-OctVPDirectorManager3,6220025,3687,24832,616
3-OctVPDirectorManager1,6404283441,6551,1943,621
3-OctVPDirectorManager20,7525,37716,1731,5331,55224,635
3-OctVPDirectorManager000000
3-OctVPDirectorManager000000
3-OctVPDirectorManager1447313610210
3-OctVPDirectorManager000000
10-OctVPDirectorManager3,0713,0815341,349012,295
10-OctVPDirectorManager3,0935,51518,26517,6765,16146,617
10-OctVPDirectorManager23,47264,01533,547 53121,249
10-OctVPDirectorManager30,2863,6256,6562010,283
10-OctVPDirectorManager3,62203,63021,8383,64429,112
10-OctVPDirectorManager1,6402543351,8831,1973,669
10-OctVPDirectorManager20,7525,37716,1731,5331,55224,635
10-OctVPDirectorManager000000
10-OctVPDirectorManager000000
10-OctVPDirectorManager14813710084
10-OctVPDirectorManager000000
17-OctVPDirectorManager3,0665,1439452,86808,956
17-OctVPDirectorManager      
17-OctVPDirectorManager23,40844,59913,89500143,164
17-OctVPDirectorManager30,83349,05113,71012062,773
17-OctVPDirectorManager3,62203,63021,8383,64429,112
17-OctVPDirectorManager1,6823225412,3073,7356,905
17-OctVPDirectorManager20,8225088,69247159,262
17-OctVPDirectorManager      
17-OctVPDirectorManager      
17-OctVPDirectorManager1771323600249
17-OctVPDirectorManager      
24-OctVPDirectorManager3,0624,0445911,86906,504
24-OctVPDirectorManager3,1124,75416,56414,7403,77339,831
24-OctVPDirectorManager23,43390,71336,09700283,023
24-OctVPDirectorManager31,76875,28319,9709095,262
24-OctVPDirectorManager3,62703,63021,8383,64429,112
24-OctVPDirectorManager1,6923015392,2632333,336
24-OctVPDirectorManager20,6734961,73182522,361
24-OctVPDirectorManager      
24-OctVPDirectorManager44890420131
24-OctVPDirectorManager1771323600249
24-OctVPDirectorManager      

 

Anonymous
Not applicable

@v-frfei-msft @Greg_Deckler - Any thing on the below posted Question mates ?

 

 

Anonymous
Not applicable

Hi Frank,

 

Thanks for sending those detailed formulaes and helping me out. I am in process of creating calendar table and got struck with 3rd calculated field "Weekend" 

 

weekend = IF(ISBLANK([Measure]),BLANK(),CALCULATE(MAX(Calenda[weekmonth]),ALLEXCEPT(Calenda,Calenda[Month])))

 

The "[Measure]" thats used in the formulae is not being recognised. I am getting below error . i dont understand what is expected over there, Could you please help me with that . 

 

Error: 

Error MEssage.PNG

 

 

 

Anonymous
Not applicable

Frank, Sorry , I didnt checked the measures below. I acheived what i am looking for . Thanks for your Quickest solution . 

 

Thanks,

G Venkatesh 

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.