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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Function returning blank in DAX

testing = 
VAR extractCampaignYear = IF (ISFILTERED('Campaign Overview'[campaign]),VALUE(MIN('Campaign Overview'[previousExtractedYear])),0)

RETURN

SUMX(
FILTER(
    SUMMARIZE (
    'Campaign Overview',
    'Campaign Overview'[campaign],
    "extractedCampaign",TRIM(MIN('Campaign Overview'[extractedCampaignName])),
    "campaignYear", VALUE(TRIM(MIN('Campaign Overview'[extractedYearFromCampaign]))),
    "Sales", SUM ( 'Campaign Overview'[sales] )
),
[campaignYear] = extractCampaignYear), [Sales])

I have written a DAX code that checks whether a campaign has been filtered and if it has it basically gets the previous campaign year and then the function should return the total sales for the previous year campaign but its just returning blank.

 

However, when I remove the extractCampaignYear and make it [campaignYear] = 2022 for example, it works.

 

Does anyone know why the campaignYear and extractCampaignYear are not matching up when they are both stored as integers as I'm using the value function so I dont know why its returning blank.
When using a variable:

joluwa_0-1699024608945.png

When I explicitly type 2022:

joluwa_1-1699024697892.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I actually managed to solve it, its because when I filter something with my slicer it also filters the summarized table so I needed to add removefilters() within my DAX code like so:

testing = 
VAR extractCampaignYear = IF (ISFILTERED('Campaign Overview'[campaign]),MIN('Campaign Overview'[previousExtractedYear]),0)

RETURN
CALCULATE(
SUMX(
FILTER(
SUMMARIZE (
'Campaign Overview',
'Campaign Overview'[campaign],
"extractedCampaign",TRIM(MIN('Campaign Overview'[extractedCampaignName])),
"campaignYear", MIN('Campaign Overview'[extractedYearFromCampaign]),
"Sales", SUM ( 'Campaign Overview'[sales] )
),
[campaignYear] = extractCampaignYear), [Sales]),
REMOVEFILTERS()
)

View solution in original post

15 REPLIES 15
AlexisOlson
Super User
Super User

I'm not seeing any unexpected behavior.

 

AlexisOlson_0-1699028926345.png

matches

AlexisOlson_1-1699028981035.png

 

Using 2022 is different when no campaign is selected because extractCampaignYear variable is 0 in this case.

AlexisOlson_2-1699029219114.png

 

Anonymous
Not applicable

I actually managed to solve it, its because when I filter something with my slicer it also filters the summarized table so I needed to add removefilters() within my DAX code like so:

testing = 
VAR extractCampaignYear = IF (ISFILTERED('Campaign Overview'[campaign]),MIN('Campaign Overview'[previousExtractedYear]),0)

RETURN
CALCULATE(
SUMX(
FILTER(
SUMMARIZE (
'Campaign Overview',
'Campaign Overview'[campaign],
"extractedCampaign",TRIM(MIN('Campaign Overview'[extractedCampaignName])),
"campaignYear", MIN('Campaign Overview'[extractedYearFromCampaign]),
"Sales", SUM ( 'Campaign Overview'[sales] )
),
[campaignYear] = extractCampaignYear), [Sales]),
REMOVEFILTERS()
)
AlexisOlson
Super User
Super User

Have you tested that your extractCampaignYear variable is returning a year rather than 0?

 

Also, if your year columns are integers, then you shouldn't need to use TRIM or VALUE to work with them.

Anonymous
Not applicable

Yes I tested it already and it returns the previous year.

joluwa_0-1699025104771.png

 

Interesting. I can't think of a reason for this behavior unless it is data type related.

 

Can you try it without the extra TRIM and VALUE after double-checking that 'Campaign Overview'[previousExtractedYear] and Campaign Overview'[extractedYearFromCampaign] are both the same data type (whole number)?

testing =
VAR extractCampaignYear =
    IF (
        ISFILTERED ( 'Campaign Overview'[campaign] ),
        MIN ( 'Campaign Overview'[previousExtractedYear] ),
        0
    )
VAR _sum =
    SUMX (
        FILTER (
            SUMMARIZE (
                'Campaign Overview',
                'Campaign Overview'[campaign],
                "extractedCampaign", TRIM ( MIN ( 'Campaign Overview'[extractedCampaignName] ) ),
                "campaignYear", MIN ( 'Campaign Overview'[extractedYearFromCampaign] ),
                "Sales", SUM ( 'Campaign Overview'[sales] )
            ),
            [campaignYear] = extractCampaignYear
        ),
        [Sales]
    )
RETURN
    extractCampaignYear

 

Anonymous
Not applicable

I tried your code and it returns the correct previous year the same way mine does. 

joluwa_0-1699025906332.png

So I dont understand why it doesnt work when adding it as a filter to say the campaign year = extractCampaignYear

Whoops. I meant to put _sum after RETURN instead of the first variable to see if removing the TRIM and VALUE did anything.

testing =
VAR extractCampaignYear =
    IF (
        ISFILTERED ( 'Campaign Overview'[campaign] ),
        MIN ( 'Campaign Overview'[previousExtractedYear] ),
        0
    )
VAR _sum =
    SUMX (
        FILTER (
            SUMMARIZE (
                'Campaign Overview',
                'Campaign Overview'[campaign],
                "extractedCampaign", TRIM ( MIN ( 'Campaign Overview'[extractedCampaignName] ) ),
                "campaignYear", MIN ( 'Campaign Overview'[extractedYearFromCampaign] ),
                "Sales", SUM ( 'Campaign Overview'[sales] )
            ),
            [campaignYear] = extractCampaignYear
        ),
        [Sales]
    )
RETURN
    _sum

 

Anonymous
Not applicable

It also returns blank, I also double checked and they are both stored as whole numbers

joluwa_0-1699026236855.png

joluwa_1-1699026283990.png

 

If you have a file you can share that reproduces this behavior, I'll take a look. Otherwise, I'm out of ideas for now.

Anonymous
Not applicable

how shall I share the pbix with you?

A link to the file publically shared online via OneDrive/SharePoint/Dropbox or a similar cloud service. Be sure it contains no sensitive data.

Anonymous
Not applicable

https://drive.google.com/file/d/1pn3tK09NnPxalh-iYhIH6oqEiO8aDs3t/view?usp=drive_link

 

The data has been sanitised so doesn't contain sensitive information

Great. Now set the permissions so that others can see it.

Currently:

AlexisOlson_0-1699028218256.png

 

Anonymous
Not applicable

Its done

Anonymous
Not applicable

I will upload the pbix file for you to take a look

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

Top Kudoed Authors