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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Jeanxyz
Impactful Individual
Impactful Individual

how to add 1 to a var

Hi,

 

I want to get the week number of next week based on filter context. Below is the measure I have written, for some reason, the var next_week always generates 1. However, var week seems to work correctly. Why add 1 to var week causes a problem?

 

weekly_cutoff =
var year=calculate(max(Dim_Calendar[Year]),keepfilters(dim_calendar[Year]))
var week=calculate(max( Dim_Calendar[WeekNumber]),keepfilters(Dim_Calendar[WeekNumber]))
var next_week = week + 1
//var cut_off=maxx(filter(Dim_Calendar,Dim_Calendar[Country]=[Selected_Country] && Dim_Calendar[Year]= benchmark_year && Dim_Calendar[WeekNumber]=[benchmark_week] && Dim_Calendar[Workday WTD]=1),Dim_Calendar[Date])
return
next_week
 
var.PNG

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

My guess is that your year and week variables are returning blank, and blank + 1 = 1.  Try returning those instead of next_week to see if they are working correctly.  Why not just use MAX(Dim_Calendar[WeekNumber])?  Why do you need the CALCULATE with KEEPFILTERS?

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

My guess is that your year and week variables are returning blank, and blank + 1 = 1.  Try returning those instead of next_week to see if they are working correctly.  Why not just use MAX(Dim_Calendar[WeekNumber])?  Why do you need the CALCULATE with KEEPFILTERS?

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Jeanxyz
Impactful Individual
Impactful Individual

I would like to correct myself, actually the problem is not due to data refreshment, but because I have a country filter in the selection pane, because there is no data between week 1-23, the var week measure only generates result from week 23, while var next_week will generate 1 since var week=0. I should have paid attention to the filtering context.

Jeanxyz
Impactful Individual
Impactful Individual

There seems to be some data refreshment issue. Now var next_week generates correct results.

Jeanxyz
Impactful Individual
Impactful Individual

Here is the result of var week. As you can see, it works properly.  By the way, you are right that I don't need keepfilters() in this measure.

 

var2.PNG

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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