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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
yamina
Helper I
Helper I

Help dax while adding column

Hi 

 

I need to duplicate these two excel formulas in power bi deskstop by adding two news colums in my table 

Can you help Me ? 

 

Date_creation_DACRIN_dossier_NUDOSN_prestation_RGOUVMin dateCondition retour 
10/04/202420030385=SI(ET(I1=I2; I2<>""); MIN(SI(I:I=I2; A:A)); "")=SIERREUR(SI(ET(A2 - L2 >= 0; A2 - L2 <= 30; J2 >= J1 + 1); "Retour dans les 30 jours"; "");"")
13/04/202470235251  
10/04/202471903631  
13/04/202472555223  
09/04/202482541481  
08/04/202483333471  
10/04/202492266552  
09/04/202494276913  
11/04/2024101433082  
11/04/2024101433094  
13/04/20241218948811  
13/04/2024121894881113/04/2024 
13/04/2024121894881113/04/2024 
13/04/2024121894881113/04/2024 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @yamina ,

 

Please try following Dax formulars.

Min date = 
VAR CurrentIndex = 'Table'[Index]
VAR PreviousDossier = MAXX(FILTER('Table', 'Table'[Index] = CurrentIndex -1), 'Table'[N_dossier_NUDOS])
VAR CurrentDossier = 'Table'[N_dossier_NUDOS]
RETURN
IF(
    PreviousDossier = CurrentDossier && CurrentDossier <> BLANK(),
    MINX(FILTER('Table', 'Table'[N_dossier_NUDOS] = CurrentDossier), 'Table'[Date_creation_DACRI]),
    BLANK()
)
Condition retour = 
VAR CurrentDossier = 'Table'[N_dossier_NUDOS]
VAR CurrentIndex = 'Table'[Index]
VAR FirstDossierIndex = MINX(FILTER('Table', 'Table'[N_dossier_NUDOS] = CurrentDossier),'Table'[Index])
VAR FirstDossierCreationDate = CALCULATE(SELECTEDVALUE('Table'[Date_creation_DACRI]), 'Table'[Index] = FirstDossierIndex , ALL())
VAR CurrentPresentation = 'Table'[N_prestation_RGOUV]
VAR PreviousPresentation =  MAXX(FILTER('Table', 'Table'[Index] = CurrentIndex -1), 'Table'[N_prestation_RGOUV])
RETURN

IFERROR(
    IF( 'Table'[Date_creation_DACRI] - FirstDossierCreationDate >= 0 && 'Table'[Date_creation_DACRI] - FirstDossierCreationDate <= 30 && CurrentPresentation >= PreviousPresentation +1,
        "Retour dans les 30 jours",
        BLANK()
    ),
    BLANK()
)

 

The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_0-1740710303288.png

 

Please see the attached pbix for reference.

 

Best Regards,
Dengliang Li

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

8 REPLIES 8
yamina
Helper I
Helper I

Sorry , 

I reformulate my request with more lines in the file. I would like to indicate for the same file number the return condition if the Presta number increases by at least 1 and if the creation date is within 30 days of the date of the 1st file

Date_creation_DACRIN_dossier_NUDOSN_prestation_RGOUVMin dateCondition retour 
10/04/202420030385=SI(ET(I1=I2; I2<>""); MIN(SI(I:I=I2; A:A)); "")=SIERREUR(SI(ET(A2 - L2 >= 0; A2 - L2 <= 30; J2 >= J1 + 1); "Retour dans les 30 jours"; "");"")
13/04/202429803685213/04/2024Retour dans les 30 jours
13/04/202429803685313/04/2024Retour dans les 30 jours
14/04/202429803685413/04/2024Retour dans les 30 jours
14/04/202429803685513/04/2024Retour dans les 30 jours
14/04/202429803685613/04/2024Retour dans les 30 jours
14/04/202429803685713/04/2024Retour dans les 30 jours
14/04/202429803685813/04/2024Retour dans les 30 jours
14/04/202429803685913/04/2024Retour dans les 30 jours
14/04/2024298036851013/04/2024Retour dans les 30 jours
14/04/2024298036851113/04/2024Retour dans les 30 jours
11/04/202437670929311/04/2024Retour dans les 30 jours
12/04/2024382449741208/04/2024Retour dans les 30 jours
12/04/202447918139312/04/2024Retour dans les 30 jours
11/04/2024489926881411/04/2024Retour dans les 30 jours
12/04/2024489926881511/04/2024Retour dans les 30 jours
12/04/2024489926881611/04/2024Retour dans les 30 jours
12/04/2024489926881811/04/2024Retour dans les 30 jours
11/04/2024513192791110/04/2024Retour dans les 30 jours
10/04/202451477461609/04/2024Retour dans les 30 jours
13/04/202451829240410/04/2024Retour dans les 30 jours
11/04/202453353783409/04/2024Retour dans les 30 jours
13/04/202453353783509/04/2024Retour dans les 30 jours
13/04/202454456236509/04/2024Retour dans les 30 jours
08/04/202454846145408/04/2024Retour dans les 30 jours
13/04/202454909754509/04/2024Retour dans les 30 jours
Anonymous
Not applicable

Hi @yamina ,

 

Please try following Dax formulars.

Min date = 
VAR CurrentIndex = 'Table'[Index]
VAR PreviousDossier = MAXX(FILTER('Table', 'Table'[Index] = CurrentIndex -1), 'Table'[N_dossier_NUDOS])
VAR CurrentDossier = 'Table'[N_dossier_NUDOS]
RETURN
IF(
    PreviousDossier = CurrentDossier && CurrentDossier <> BLANK(),
    MINX(FILTER('Table', 'Table'[N_dossier_NUDOS] = CurrentDossier), 'Table'[Date_creation_DACRI]),
    BLANK()
)
Condition retour = 
VAR CurrentDossier = 'Table'[N_dossier_NUDOS]
VAR CurrentIndex = 'Table'[Index]
VAR FirstDossierIndex = MINX(FILTER('Table', 'Table'[N_dossier_NUDOS] = CurrentDossier),'Table'[Index])
VAR FirstDossierCreationDate = CALCULATE(SELECTEDVALUE('Table'[Date_creation_DACRI]), 'Table'[Index] = FirstDossierIndex , ALL())
VAR CurrentPresentation = 'Table'[N_prestation_RGOUV]
VAR PreviousPresentation =  MAXX(FILTER('Table', 'Table'[Index] = CurrentIndex -1), 'Table'[N_prestation_RGOUV])
RETURN

IFERROR(
    IF( 'Table'[Date_creation_DACRI] - FirstDossierCreationDate >= 0 && 'Table'[Date_creation_DACRI] - FirstDossierCreationDate <= 30 && CurrentPresentation >= PreviousPresentation +1,
        "Retour dans les 30 jours",
        BLANK()
    ),
    BLANK()
)

 

The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_0-1740710303288.png

 

Please see the attached pbix for reference.

 

Best Regards,
Dengliang Li

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

Hello 

As i understand I need to add an index column, but it takes a very long time because my table has 2 millions lines. so it is impossible. In addition I have to sort before the columns N_dossier_ num . and N_prestation_ RGOUV by asc. It is very heavy because my report use summarize  table from an another semantic model. so I don't know how to simplify this. 

Anonymous
Not applicable

Thanks for the reply from rajendraongole1, please allow me to provide another insight.

Hi @yamina ,

 

Please refers to the following steps.

Add an index column to the table in the Power Query editor.

vdengllimsft_0-1740540309375.png

 

Use the following DAX formulas to create the 'Min date' column and the 'Condition retour' column.

 

 

Min date = 
VAR CurrentIndex = [Index]
VAR PreviousDossier = MAXX(FILTER('Table', [Index] = CurrentIndex -1),[N_dossier_NUDOS])
VAR CurrentDossier = 'Table'[N_dossier_NUDOS]
RETURN
IF(
    PreviousDossier = CurrentDossier && CurrentDossier <> BLANK(),
    MINX(FILTER('Table', [N_dossier_NUDOS] = CurrentDossier), [Date_creation_DACRI]),
    BLANK()
)

 

Condition retour  = 
VAR CurrentIndex ='Table'[Index]
VAR CurrentPresentation = 'Table'[N_prestation_RGOUV]
VAR PreviousPresentation =  MAXX(FILTER('Table', [Index] = CurrentIndex -1), [N_prestation_RGOUV])
RETURN
IFERROR(
    IF( [Date_creation_DACRI] - [Min date] >=0  && [Date_creation_DACRI] - [Min date] <= 30 && CurrentPresentation >= PreviousPresentation +1,
        "Retour dans les 30 jours",
        BLANK()
    ),
    BLANK()
)

 

The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_1-1740540531413.png

 

Please see the attahced pbix for reference.

 

Best Regards,
Dengliang Li

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

rajendraongole1
Super User
Super User

Hi @yamina  - you can create two calculated columns using DAX.

 

Min date =
VAR CurrentDossier = 'YourTable'[N_dossier_NUDOS]
RETURN
IF(
COUNTROWS(FILTER('YourTable', 'YourTable'[N_dossier_NUDOS] = CurrentDossier)) > 1,
CALCULATE(MIN('YourTable'[Date_creation_DACRI]),
ALLEXCEPT('YourTable', 'YourTable'[N_dossier_NUDOS])
),
BLANK()
)

 

This column checks if the difference between Date_creation_DACRI and Min date is between 0 and 30, and if N_prestation_RGOUV has increased.

 

Condition retour =
VAR MinDate = 'YourTable'[Min date]
VAR CurrentDate = 'YourTable'[Date_creation_DACRI]
VAR CurrentDossier = 'YourTable'[N_dossier_NUDOS]
VAR CurrentPrestation = 'YourTable'[N_prestation_RGOUV]

VAR PreviousPrestation =
CALCULATE(
MAX('YourTable'[N_prestation_RGOUV]),
FILTER(
'YourTable',
'YourTable'[N_dossier_NUDOS] = CurrentDossier &&
'YourTable'[Date_creation_DACRI] < CurrentDate
)
)

RETURN
IF(
NOT ISBLANK(MinDate) &&
CurrentDate - MinDate >= 0 &&
CurrentDate - MinDate <= 30 &&
CurrentPrestation >= PreviousPrestation + 1,
"Retour dans les 30 jours",
BLANK()
)

 

replace with your table name as per the model. hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





hi @rajendraongole1 

See the error message when I try your solution. The Min date is ok but the condition retour returns this error  " Les opérations DAX de comparaison ne prennent pas en charge la comparaison des valeurs de type Text avec des valeurs de type Number. Utilisez la fonction VALUE ou FORMAT pour convertir une des valeurs." because the N_dossier is in text format. 

Hi @yamina - can you try the modified one.

Condition retour =
VAR MinDate = 'YourTable'[Min date]
VAR CurrentDate = 'YourTable'[Date_creation_DACRI]
VAR CurrentDossier = 'YourTable'[N_dossier_NUDOS] -- Ensure it's text
VAR CurrentPrestation = 'YourTable'[N_prestation_RGOUV]

VAR PreviousPrestation =
CALCULATE(
MAX('YourTable'[N_prestation_RGOUV]),
FILTER(
'YourTable',
FORMAT('YourTable'[N_dossier_NUDOS], "@") = FORMAT(CurrentDossier, "@") && -- Ensure text comparison
'YourTable'[Date_creation_DACRI] < CurrentDate
)
)

RETURN
IF(
NOT ISBLANK(MinDate) &&
CurrentDate - MinDate BETWEEN 0 AND 30 &&
NOT ISBLANK(PreviousPrestation) &&
CurrentPrestation > PreviousPrestation,
"Retour dans les 30 jours",
BLANK()
)

 

here, FORMAT(N_dossier_NUDOS, "@") to force text comparison.Ensured PreviousPrestation isn't blank before checking the condition.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





I try with this solution because beetween function didn't work 

Condition retour =
VAR MinDate = 'TDB 24 mois'[Min date]
VAR CurrentDate = 'TDB 24 mois'[Date_creation_DACRe]
VAR CurrentDossier = FORMAT('TDB 24 mois'[N_dossier_NUDOS], "@")
VAR CurrentPrestation = 'TDB 24 mois'[N_prestation_RGOUV]

VAR PreviousPrestation =
CALCULATE(
    MAX('TDB 24 mois'[N_prestation_RGOUV]),
    FILTER(
        'TDB 24 mois',
        FORMAT('TDB 24 mois'[N_dossier_NUDOS], "@") = CurrentDossier &&
        'TDB 24 mois'[Date_creation_DACRe] < CurrentDate
    )
)

VAR IsMinDateValid = NOT ISBLANK(MinDate)
VAR IsDateInRange = CurrentDate >= MinDate && CurrentDate <= MinDate + 30
VAR IsPreviousPrestationValid = NOT ISBLANK(PreviousPrestation)
VAR IsCurrentPrestationHigher = CurrentPrestation > PreviousPrestation

RETURN
IF(
    IsMinDateValid &&
    IsDateInRange &&
    IsPreviousPrestationValid &&
    IsCurrentPrestationHigher,
    "Retour dans les 30 jours",
    BLANK()
)

 

 

yamina_0-1741690040089.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.