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
linusb
Frequent Visitor

Help with measure

Hello,

I'm new to PowerBI and I'm trying to get a measure working that looks at what WeekNum is selected, and from that calculates the available capacity.

 

I've created 2 measures.

// To select to current week

Selected Week = CALCULATE(MIN(Dates[Weeknum]),
FILTER(Dates,
Dates[IsDateHistory] = 0)
)
// To calculate remaining Manufacturing time
Available Capacity Inc Past =
CALCULATE([Remaining Manuf Time],
FILTER(ALL(Dates),
Dates[Weeknum] <= [Selected Week]
)
 
No matter what weeknum I select in my graph the wrong amount is calculated, but the meaure Selected Week calculates correctly. If I change the measure "Selected week" to a hardcoded number (i.e 27), then the correct value is calculated.
Can someone help me understand what isn't working.
 
Thanks
Linus
1 ACCEPTED SOLUTION

Hi @linusb ,

 

Maybe you can do like this.

Create  a calculated column like this and use hierarchical slicer.

 

Mark the current weeknum = 
VAR x = WEEKNUM( TODAY(), 2 )
RETURN
IF(
    x = [Weeknum],
    "Current weeknum",
    "Other weeknum"
)

q2.PNG

 

q3.PNG

After you set the default option of the slicer, as the data is updated, the default option of the slicer is always the current week number.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @linusb ,

 

You don't need to create the [Selected Week ] measure, just need to like this.

Available Capacity Inc Past = 
CALCULATE(
    [Remaining Manuf Time],
    FILTER(
        ALL(Dates),
        Dates[Weeknum] <= MAX(Dates[Weeknum])
    )
)

vvv3.PNGvvv4.PNG

Hope this is what you want, if not please give example data and carefully describe the results you want.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the replys.

 

This solution almost does the trick. The problem is, that I want the "Selected Week" to be the current week, when no weeknum is selected. 

 

If I have a variable that I want to use in serveral measures, is it better to create the variable as it's own measure or define it as "local" variable in each measure?

 

I've also tried using:

Selected Week = SELECTEDVALUE(Dates[Weeknum])

 

Available Capacity Include Past = 
 CALCULATE([Remaining Manuf Time],
            FILTER(ALL(Dates),
                            Dates[Weeknum] <= [Selected Week])
                                )
            )

This gives my the wrong result (always 16676,75 not matter what week I select) 16677 equals the total amount of remaining manufacturing time, calculated by the measure [Remaining Manuf Time].

 

If I merge [Selected Week] into the measure:

Available Capacity Include Past = 
 CALCULATE([Remaining Manuf Time],
            FILTER(ALL(Dates),
                            Dates[Weeknum] <= SELECTEDVALUE(Dates[Weeknum])
                                )
            )

Then the measure will calculate the correct values.

 

I don't understand, why this is happening.

 

Best regards,

// Linus

Hi @linusb ,

 

Maybe you can do like this.

Create  a calculated column like this and use hierarchical slicer.

 

Mark the current weeknum = 
VAR x = WEEKNUM( TODAY(), 2 )
RETURN
IF(
    x = [Weeknum],
    "Current weeknum",
    "Other weeknum"
)

q2.PNG

 

q3.PNG

After you set the default option of the slicer, as the data is updated, the default option of the slicer is always the current week number.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

@linusb 

 

could you please share the sample data?

 

What is the output for the first measure? 27?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




parry2k
Super User
Super User

@linusb without looking how are the relationship etc , try following

 

// To select to current week
Selected Week = CALCULATE(MIN(Dates[Weeknum]),
Dates[IsDateHistory] = 0
)

// To calculate remaining Manufacturing time
Available Capacity Inc Past =
CALCULATE([Remaining Manuf Time],
FILTER(ALL(Dates),
Dates[Weeknum] <= [Selected Week]
)
)

or

// To calculate remaining Manufacturing time
Available Capacity Inc Past =
VAR __selectedWeek =  CALCULATE(MIN(Dates[Weeknum]),
Dates[IsDateHistory] = 0
)
RETURN
CALCULATE([Remaining Manuf Time],
FILTER(ALL(Dates),
Dates[Weeknum] <= __selectedWeek
)
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.