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
BenMagn
New Member

First occurence with multiple conditions

Hi, I am new to DAX and would like to create a measure that produce a column called [Rookie year] to count the first occurence of an individual that purchased an item based on other variables. 

 

those are the other conditions to be considered in order to be counted as first occurence : 

 

- His client number wich is unique to him and stay's the same year after year is called [N certificat]

- In the column [Statut certificat] It as to be "Permanent"

- The date of [Date certificat] as to be within 5 years of the date of purchase wich is the column [Date emission permis] in order to count

 

So each [N certificat] as to appear only once in the column rookie year.

 

see picture below for a more visual look of an example table. the datas are not the real datas so the occurence dont match.

 

BenMagn_0-1674246276067.png

 

Ive fiddled with some of the formulas found in the forum but couldnt find one that I am able to translate to my needs. 

 

Thanks very much !

1 ACCEPTED SOLUTION

Hi @BenMagn ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create a measure as below to get it:

Rookie year = 
VAR _selncer =
    SELECTEDVALUE ( 'Table'[N certificat] )
VAR _mindep =
    CALCULATE (
        MIN ( 'Table'[Date emission permis] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[N certificat] = _selncer )
    )
VAR _tab =
    CALCULATETABLE (
        VALUES ( 'Table'[N certificat] ),
        FILTER (
            'Table',
            'Table'[N certificat] = _selncer
                && 'Table'[Date emission permis] = _mindep
                && 'Table'[Statut certificat] = "Permanent"
                && 'Table'[Date emission permis] - 'Table'[Date certificat] <= 5
        )
    )
RETURN
    IF ( _selncer IN _tab, 1, 0 )

yingyinr_0-1674546750922.png

If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
BenMagn
New Member

Hope this is easier to understand ! thanks!

BenMagn_2-1674482932971.png

 

 

 

Hi @BenMagn ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create a measure as below to get it:

Rookie year = 
VAR _selncer =
    SELECTEDVALUE ( 'Table'[N certificat] )
VAR _mindep =
    CALCULATE (
        MIN ( 'Table'[Date emission permis] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[N certificat] = _selncer )
    )
VAR _tab =
    CALCULATETABLE (
        VALUES ( 'Table'[N certificat] ),
        FILTER (
            'Table',
            'Table'[N certificat] = _selncer
                && 'Table'[Date emission permis] = _mindep
                && 'Table'[Statut certificat] = "Permanent"
                && 'Table'[Date emission permis] - 'Table'[Date certificat] <= 5
        )
    )
RETURN
    IF ( _selncer IN _tab, 1, 0 )

yingyinr_0-1674546750922.png

If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
FreemanZ
Super User
Super User

hi @BenMagn 

Unable to understand your expectation, could you provide also the expected result?

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.