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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
andicornejo12
Helper I
Helper I

Formula not working without adding the year on the visual

Hello all,

 

I have a formula (not time intelligence) to show the Calendar Week (CW) of the previous year (PY).

andicornejo12_1-1700563948418.png

 

However the formula doesnt work when I dont have the year in the table, please see below. Is there any tweak I can do to it so that it will still show regardless if the year field is there or not.

andicornejo12_0-1700563898056.png

 

Here the formula:

 

PY CW =

VAR _selectedYear = SELECTEDVALUE('Date'[Year])

 

VAR _selectedWeek = SELECTEDVALUE('Date'[Week])

 

RETURN

 

IF(

    NOT ISINSCOPE('Date'[Week]),

    CALCULATE(

        SUM(Orders[Sales]),

        FILTER(

            ALL('Date'),

            'Date'[Year] = _selectedYear -1

        )

    ),

    CALCULATE(

        SUM(Orders[Sales]),

        FILTER(

            ALL('Date'),

            'Date'[Year] = _selectedYear -1 &&

            'Date'[Week] = _selectedWeek

        )

    )

)

 

Also why in the table that is working the totals are not displayed?

 

Thank you very much!!

2 ACCEPTED SOLUTIONS
Rupak_bi
Resolver II
Resolver II

Its not wirking as you are using Selected value. So if there is no year column, the selected value is blank. Insted selected value, you may try max of date. Is also not showing the total as at total level your conditions doesnot matches. 

View solution in original post

v-zhangti
Community Support
Community Support

Hi, @andicornejo12 

 

You can try the following formula.

PY CW =
VAR _selectedYear =
    MAX ( 'Date'[Year] )
VAR _selectedWeek =
    MAX ( 'Date'[Week] )
RETURN
    IF (
        NOT ISINSCOPE ( 'Date'[Week] ),
        CALCULATE (
            SUM ( Orders[Sales] ),
            FILTER ( ALL ( 'Date' ), 'Date'[Year] = _selectedYear - 1 )
        ),
        CALCULATE (
            SUM ( Orders[Sales] ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Year] = _selectedYear - 1
                    && 'Date'[Week] = _selectedWeek
            )
        )
    )

If this does not solve your problem, please provide more information about the data.

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @andicornejo12 

 

You can try the following formula.

PY CW =
VAR _selectedYear =
    MAX ( 'Date'[Year] )
VAR _selectedWeek =
    MAX ( 'Date'[Week] )
RETURN
    IF (
        NOT ISINSCOPE ( 'Date'[Week] ),
        CALCULATE (
            SUM ( Orders[Sales] ),
            FILTER ( ALL ( 'Date' ), 'Date'[Year] = _selectedYear - 1 )
        ),
        CALCULATE (
            SUM ( Orders[Sales] ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Year] = _selectedYear - 1
                    && 'Date'[Week] = _selectedWeek
            )
        )
    )

If this does not solve your problem, please provide more information about the data.

 

Best Regards,

Community Support Team _Charlotte

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

 

Rupak_bi
Resolver II
Resolver II

Its not wirking as you are using Selected value. So if there is no year column, the selected value is blank. Insted selected value, you may try max of date. Is also not showing the total as at total level your conditions doesnot matches. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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