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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
AH2022
Helper II
Helper II

Power BI Dax - How to use a selected date value in a measure

Hi All,

 

I want to make a calculation based on a fiscal period. The code DAX for 22-23 (2022/04/01-2023/03/31)  works.

NbreClientsContractNOTRenewed22-23 =

CALCULATE(

COUNT(TableClients[id]), FILTER(TableContracts, TableContracts[ContractsEndingOn(Future)]=0 && TableContracts[ContractsEndingOn(Past)]<=DATE(2023,03,31) &&

TableContracts [ContractsEndingOn (Past)]>=DATE(2022,04,01)))

 

How can I write the code, and calculate based on a fiscal period selected by the user , within a slicer?

User selects a FiscalYear (From a Slicer)

DimDate[Date] between

AH2022_0-1659765526081.png

 

NbreClientsContractsNOTRenewedFYSelectedByUser =

CALCULATE(

COUNT(TableClients[id]), FILTER(TableContracts, TableContracts[InstallmentsEndingOn(Future)]=0 &&

TableContracts[InstallmentsEndingOn(Past)]= FYSelectedByUser

//Calculates NbreClientsContracts finishing FY Selected By User

Thank You.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please try the below if it works.

 

NbreClientsContractNOTRenewed22-23 =
VAR _minselecteddate =
    MIN ( Calendartable[Date] )
VAR _maxselecteddate =
    MAX ( Calendartable[Date] )
RETURN
    CALCULATE (
        COUNT ( TableClients[id] ),
        FILTER (
            TableContracts,
            TableContracts[ContractsEndingOn(Future)] = 0
                && TableContracts[ContractsEndingOn(Past)] <= _maxselecteddate
                && TableContracts[ContractsEndingOn (Past)] >= _minselecteddate
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please try the below if it works.

 

NbreClientsContractNOTRenewed22-23 =
VAR _minselecteddate =
    MIN ( Calendartable[Date] )
VAR _maxselecteddate =
    MAX ( Calendartable[Date] )
RETURN
    CALCULATE (
        COUNT ( TableClients[id] ),
        FILTER (
            TableContracts,
            TableContracts[ContractsEndingOn(Future)] = 0
                && TableContracts[ContractsEndingOn(Past)] <= _maxselecteddate
                && TableContracts[ContractsEndingOn (Past)] >= _minselecteddate
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you @Jihwan_Kim ,

I need to refine my question.

 

ContractsEndingOn(Past) is a calculated column.

The calculated column ContractsEndingOn(Past) allows the user to specify the “fiscal period” within a slicer and keeps the implicit Filter of the report on the page. Therefore, it filters my visual and the calculation of the respective number of customers is done according to the ContractsEndingOn(Past) ( “fiscal period” selected by the user.)

 

The problem arises when I want to make a table summarizing the number of clients who have renewed their contract, sorted by fiscal period.

 

Because a contract can be signed for example in 22-23 and can end in 26-27.

I need to display the fiscal period, based on the contract end date.

 

I have this:

AH2022_3-1659800685775.png

 

I need to calculate the “Fiscal Year” based on the column TableContracts[ContractsEndingOn(Past)] :

 

AH2022_4-1659800700161.png

 

In summary, I need to create a fiscal year column (CalculatedColumn)  from another Date calculated column TableContracts[ContractsEndingOn(Past)].

01/April/Year1 TO 31/March/Year2  returns Year1 – Year2

01/April/2022 TO 31/March/2023  returns 22-23 OR 2022-2023 

 

Thank you !

Hi,

Sorry that it is difficult to understand the problem.

If it is OK with you, please share your sample pbix file's link and the expected outcome of the visualization, and then I can try to look into it to come up with a more accurate solution.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi Kim,

I accepted your answer as a solution for the first part of the question. Thank You.

 

For the 2nd part, (determine Fiscal Year from a calculated column) this post helped me. Solved: Re: Fiscal Year Calculated Columns - Microsoft Power BI Community  

 

Good day.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.