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
ArquimedesP
Helper I
Helper I

HELP WHIT MY DAX

Hi guys! I kind of new using Power Bi and stil have some issiues using DAX whit calculates columns.

I have this data:

NUMERO_CARPETA_NUFECHA_MOVIMIENTOSECTOR_SOLICITUD_ACTUALSECTOR_SOLICITUD_ANTERIORFECHA_SECTOR_ANTERIOR
15/6/2008OYCEL26/5/2008
110/6/2008ACL10/6/2008
126/5/2008ACAC26/5/2008
110/6/2008LOYCE5/6/2008
126/5/2008LAC26/5/2008
1004423/8/2017RBO23/8/2017
1004423/8/2017BOAC24/7/2017
100446/9/2017GGR23/8/2017
100446/10/2017GGAC8/9/2017
100448/9/2017ACGG6/9/2017
100446/10/2017ACGG6/10/2017
1004424/7/2017ACAC24/7/2017

 

I want to add calculated columns like this:

 

 

NUMERO_CARPETA_NUFECHA_MOVIMIENTO SECTOR_SOLICITUD_ACTUALSECTOR_SOLICITUD_ANTERIORFECHA_SECTOR_ANTERIORFECHA SECTOR ANTERIORSECTOR ANTERIORFECHA SECTOR ACTUALSECTOR ACTUAL
15/6/2008OYCEL26/5/200810/6/2008L10/6/2008L
110/6/2008ACL10/6/200810/6/2008L10/6/2008L
126/5/2008ACAC26/5/200810/6/2008L10/6/2008L
110/6/2008LOYCE5/6/200810/6/2008L10/6/2008L
126/5/2008LAC26/5/200810/6/2008L10/6/2008L
1004423/8/2017RBO23/8/2017

06/10/2017

GG

24/07/2017

AC
1004423/8/2017BOAC24/7/201706/10/2017GG24/07/2017AC
100446/9/2017GGR23/8/201706/10/2017GG24/07/2017AC
100446/10/2017GGAC8/9/201706/10/2017GG24/07/2017AC
100448/9/2017ACGG6/9/201706/10/2017GG24/07/2017AC
100446/10/2017ACGG6/10/201706/10/2017GG24/07/2017AC
1004424/7/2017ACAC24/7/201706/10/2017GG24/07/2017AC

 

For "Fecha Sector Anterior" column i used this DAX= 

CALCULATE(MAX(VW_Movimiento_Solicitud[Fecha_Sector_Anterior]);ALLEXCEPT(VW_Movimiento_Solicitud;VW_Movimiento_Solicitud[Numero_Carpeta_Nu]))
 
For "Sector Anterior" column i used this DAX=
VAR FECHA_ANTERIOR = CALCULATE(MAX(VW_Movimiento_Solicitud[Fecha_Sector_Anterior]);ALLEXCEPT(VW_Movimiento_Solicitud;VW_Movimiento_Solicitud[Fecha_Sector_Anterior]))
RETURN
CALCULATE(SELECTEDVALUE(VW_Movimiento_Solicitud[Sector_Solicitud_Anterior]);Fecha_Anterior=(VW_Movimiento_Solicitud[Fecha Sector Anterior]))
 
For "Fecha Sector Actual" i used this DAX =
CALCULATE(MAX(VW_Movimiento_Solicitud[Fecha_Movimiento]);ALLEXCEPT(VW_Movimiento_Solicitud;VW_Movimiento_Solicitud[Numero_Carpeta_Nu]))
 
For "Sector Actual" i used this DAX=
IF(VW_Movimiento_Solicitud[Fecha_Movimiento]=VW_Movimiento_Solicitud[Fecha Sector Actual];VW_Movimiento_Solicitud[Sector_Solicitud_Actual];"") (This is the only dax i used that worked, others gave me a circular dependency error).
 
 
 

 

7 REPLIES 7
kentyler
Solution Sage
Solution Sage

So you have Carpetas, Dates, and Sectors

Are you trying to calculate the previous sector a carpeta was in (that is, where it was before it moved ) ?





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Yes, that is correct Ken. I want to know the last sector a carpeta was in and the actual sector it's in. 

I reduced your data to a small sample previousdate.PNG
There are a couple of business rules you have to decide on. 
1) if 2 entries have the same date, can one be "previous" to the other. If it can, is that based on the order the records were entered ?
2) if the previous entry for a given record is for a day that also has 2 entries on the same day, which of the 2 entries should be selected, again, should it be based on the order the records were entered in ?

If you make those decisions, then I can write the DAX to select the values you want.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


There are a couple of business rules you have to decide on. 
1) if 2 entries have the same date, can one be "previous" to the other. If it can, is that based on the order the records were entered ?

A- Correct, based on the order the data was entered. But I don't manipulate those entries, this data is automatically loaded from another database.
2) if the previous entry for a given record is for a day that also has 2 entries on the same day, which of the 2 entries should be selected, again, should it be based on the order the records were entered in ?

A- It should take the last entry that was entered into the system. When someone uploads the data to the system, it only takes the date (it does not take hours, minutes or seconds). So if there are 2 entries the same day, you should be able to select the last one entered.

 

I just want to show where that folder is currently and where it was before that.

I understand... the question is when there are 2 rows with the same date, which one do you select to represent "before that'





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


I have not way to know that. Maybe a DAX o QUERY to take the same order that it comes from the data base.

The strategy illustrated here https://www.burningsuit.co.uk/blog/2019/11/find-a-value-in-the-previous-row/  should work for you... for some reason I can't get it to work in my example database.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


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.

Top Solution Authors