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
mdaamirkhan
Post Prodigy
Post Prodigy

Current year and Current year +1 now working

Hi All

 

I need help on dax query as Current year and Current year +1 now working screenshot below and the query. If can provide the solution with dax  it will be good

Estimated revenue Current year +1 =
var thisYear = year(now())+1
var NSM = DISTINCTCOUNT(Input_Contract_Report[months])
var val =
CALCULATE( NSM,
Filter (Input_Contract_Report, Input_Contract_Report[Active] = "Yes"),
Filter ( Input_Contract_Report, Input_Contract_Report[End Date].[Year] = thisYear),
ALLEXCEPT(Invoice_Report,Invoice_Report[Contract Code])
)
return
--NSM
val * [Averge Revenue]

 

Capture.JPG

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hello @mdaamirkhan ,

 

you save NSM as a variable, but a variable is always static.

This means the moment you set the variable NSM the value is 10.

 

When you use this variable in the Calculate function, the value is already set to 10.

Try to use the DISTINCTCOUNT function in the CALCULATE function, then the result is evaluated in the right context:

Estimated revenue Current year +1 = 
VAR thisYear = YEAR ( NOW () ) + 1
VAR val =
    CALCULATE (
        DISTINCTCOUNT ( Input_Contract_Report[months] ),
        FILTER ( Input_Contract_Report, Input_Contract_Report[Active] = "Yes" ),
        FILTER (
            Input_Contract_Report,
            Input_Contract_Report[End Date].[Year] = thisYear
        ),
        ALLEXCEPT ( Invoice_Report, Invoice_Report[Contract Code] )
    )
RETURN
    --NSM
    val * [Averge Revenue]

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi

View solution in original post

3 REPLIES 3
selimovd
Super User
Super User

Hello @mdaamirkhan ,

 

you save NSM as a variable, but a variable is always static.

This means the moment you set the variable NSM the value is 10.

 

When you use this variable in the Calculate function, the value is already set to 10.

Try to use the DISTINCTCOUNT function in the CALCULATE function, then the result is evaluated in the right context:

Estimated revenue Current year +1 = 
VAR thisYear = YEAR ( NOW () ) + 1
VAR val =
    CALCULATE (
        DISTINCTCOUNT ( Input_Contract_Report[months] ),
        FILTER ( Input_Contract_Report, Input_Contract_Report[Active] = "Yes" ),
        FILTER (
            Input_Contract_Report,
            Input_Contract_Report[End Date].[Year] = thisYear
        ),
        ALLEXCEPT ( Invoice_Report, Invoice_Report[Contract Code] )
    )
RETURN
    --NSM
    val * [Averge Revenue]

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi

its not working same issue. I have many-to-many relationship as well
Capture.JPG

what about this var thisYear = YEAR(NOW())+1

will it work in the query. 

as per your query will it show 2022 value as well.

and if I want create table with a year use in slicer then how will used in the query

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.