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
jesus_rc
Regular Visitor

Percentage of total (context and model)

Hi,

I am creating a measure to calculate a "% of total" taking in the context the date field, but it only works if the date field is in the same table as the other values, i.e., when I try to use the date field from my DimCalendar it won't work. What am I doing wrong? Is it the modelling or the DAX?

 

PBIX file avaliable in my OneDrive here.

 

This works:

 

% of year total = 
VAR amount = [Expenses]
VAR TOT =
CALCULATE(
    [Expenses],
    ALLEXCEPT(English, English[Year]) // English[Year] is a redundant calc col
)

RETURN
IF(
    SELECTEDVALUE(English[Year], "-") <> "-",
    DIVIDE (amount , TOT, "Error"),
    "Select a year"
)

 

 

This doesn't:

 

% of year total = 
VAR amount = [Expenses]
VAR TOT =
CALCULATE(
    [Expenses],
    ALLEXCEPT(DimCalendar, DimCalendar[Year]) // This won't work
)

RETURN
IF(
    SELECTEDVALUE(English[Year], "-") <> "-",
    DIVIDE (amount , TOT, "Error"),
    "Select a year"
)

 

 

Thanks in advance for any tip.

1 ACCEPTED SOLUTION
jesus_rc
Regular Visitor

Hi @puneetvijwani ,

Thankss a lot for your support. You gave the insight I needed!

It worked with:

 

% of year total =
VAR amount = [Expenses]
VAR TOT =
CALCULATE(
    [Expenses],
   REMOVEFILTERS(English[Department) // instead of REMOVEFILTERS(DimCalendar).
)

 

RETURN
IF(
    SELECTEDVALUE(DimCalendar[Year], "-") <> "-",
    DIVIDE (amount , TOT, "Error"),
    "Select a year")
 
I wasn't familiar with REMOVEFILTERS, guess I'll be using it more from now on.

View solution in original post

2 REPLIES 2
jesus_rc
Regular Visitor

Hi @puneetvijwani ,

Thankss a lot for your support. You gave the insight I needed!

It worked with:

 

% of year total =
VAR amount = [Expenses]
VAR TOT =
CALCULATE(
    [Expenses],
   REMOVEFILTERS(English[Department) // instead of REMOVEFILTERS(DimCalendar).
)

 

RETURN
IF(
    SELECTEDVALUE(DimCalendar[Year], "-") <> "-",
    DIVIDE (amount , TOT, "Error"),
    "Select a year")
 
I wasn't familiar with REMOVEFILTERS, guess I'll be using it more from now on.
puneetvijwani
Resolver IV
Resolver IV

HI @jesus_rc  try uing the below DAX
And use the Year column from DIm calender table in your Filter visual Instead of english table's year ; let me know if that works 

 

% of year total =
VAR amount = [Expenses]
VAR TOT =
CALCULATE(
    [Expenses],
   REMOVEFILTERS(DimCalendar)
)

RETURN
IF(
    SELECTEDVALUE(DimCalendar[Year], "-") <> "-",
    DIVIDE (amount , TOT, "Error"),
    "Select a year")

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.

Top Solution Authors