We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hola a todos
Necesito ayuda para convertir una consulta SQL a DAX con un ligero cambio.
La siguiente consulta me dará lo que necesito para el mes de abril, pero lo que necesito es que mi DAX sea dinámico en función del mes seleccionado.
Por lo tanto, si mi mes actual es marzo, por ejemplo, el DAX debe darme reservas para la fecha de reserva entre 20210301 y 20210330 y donde la fecha de cancelación no está entre 20210301 y 20210330 y la fecha de caducidad no está entre 20210301 y 20210330. Y del mismo modo si se selecciona cualquier otro mes. Espero que esto tenga sentido!
Gracias por su ayuda!
Solved! Go to Solution.
@Kartiklal03
Los modifiqué:
Bookings =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
DISTINCTCOUNT ( Booking[Booking Number] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
OR(
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate ),
ISBLANK( Booking[Cancellation Date] )
)
&&
OR(
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate ),
ISBLANK( Booking[Expiry Date] )
)
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
Revenue =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
sum ( Booking[Booking Price EUR] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
OR(
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate ),
ISBLANK( Booking[Cancellation Date] )
)
&&
OR(
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate ),
ISBLANK( Booking[Expiry Date] )
)
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
@Kartiklal03
Hola, inserte una segmentación de datos en el informe e incluya la fecha de reserva y filtre a abril. A continuación, agregue las dos medidas siguientes:
Bookings =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
DISTINCTCOUNT ( Booking[Booking Number] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate )
&&
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate )
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
Revenue =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
SUM( Booking[Booking Price EUR] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate )
&&
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate )
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
No @Fowmy,
Gracias por su respuesta, pero no creo que me dará lo que estoy buscando.
Necesito poder mostrar mis datos para cada mes calendario en el año, similar a la captura de pantalla a continuación.
@Kartiklal03
Debe proporcionar más información sobre el modelo y cómo desea visualizarlo. ¿Tienes una tabla de calendario?
Mejor, comparta un archivo PBIX de ejemplo.
No @Fowmy,
Puede obtener una muestra de pbix en el siguiente enlace
https://www.dropbox.com/s/dvd12rvzoowxont/Sample.pbix?dl=0
@Kartiklal03
Por favor, compruebe mi respuesta original, modifiqué la fórmula y adjunto el archivo.
No @Fowmy,
Gracias por eso.
¿Cómo incluo "si la fecha de cancelación o caducidad está en blanco"? Estoy teniendo algunos problemas con esto.
Modifiqué el DAX para incluir si la fecha de cancelación o la fecha de caducidad están en blanco, pero no me está dando la cifra correcta.
Bookings :=
VAR __startdate =
MIN ( 'Calendar'[Date Key] )
VAR __enddate =
MAX ( 'Calendar'[Date Key] )
RETURN
CALCULATE (
DISTINCTCOUNT ( Booking[Booking Number] ),
FILTER (
ALL ( Booking ),
Booking[Booking Date] >= __startdate
&& Booking[Booking Date] <= __enddate
&& NOT ( Booking[Cancellation Date] >= __startdate
&& Booking[Cancellation Date] <= __enddate )
|| ISBLANK ( Booking[Cancellation Date] )
&& NOT ( Booking[Expiry Date] >= __startdate
&& Booking[Expiry Date] <= __enddate )
|| ISBLANK ( Booking[Expiry Date] )
),
Booking[Channel Name] = "Internet",
Booking[Original Booking Status] = "FIRM"
|| Booking[Original Booking Status] = "Normal"
|| Booking[Original Booking Status] = "OP"
|| Booking[Original Booking Status] = "Requested"
)
@Kartiklal03
Los modifiqué:
Bookings =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
DISTINCTCOUNT ( Booking[Booking Number] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
OR(
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate ),
ISBLANK( Booking[Cancellation Date] )
)
&&
OR(
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate ),
ISBLANK( Booking[Expiry Date] )
)
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
Revenue =
var __startdate = min( 'Calendar'[Date Key] )
var __enddate = max( 'Calendar'[Date Key] )
return
CALCULATE (
sum ( Booking[Booking Price EUR] ),
FILTER(
ALL(Booking),
Booking[Booking Date] >= __startdate &&
Booking[Booking Date] <= __enddate &&
OR(
NOT( Booking[Cancellation Date] >= __startdate &&
Booking[Cancellation Date] <= __enddate ),
ISBLANK( Booking[Cancellation Date] )
)
&&
OR(
NOT( Booking[Expiry Date] >= __startdate &&
Booking[Expiry Date] <= __enddate ),
ISBLANK( Booking[Expiry Date] )
)
),
Booking[Channel Name] = "Internet"&&
Booking[Original Booking Status] IN {"Firm", "Normal", "Requested", "OP"}
)
No @Fowmy,
Gracias de nuevo. Su DAX modificado funciona, pero de nuevo no estoy obteniendo las cifras correctas para reservas o ingresos.
La consulta SQL original devuelve alrededor de 4900 reservas para el mes de abril, mientras que dax devuelve alrededor de 3100 reservas.
@Kartiklal03
Mejor revise las dos tablas de un mes en particular y averigüe qué registros no se han reconciliado
No @Fowmy,
¡Ignora mi mensaje anterior! Su DAX modificado funciona perfectamente y ahora me está dando exactamente lo que estaba buscando.
Gracias por su ayuda. Voy a marcar ese post como la solución ahora.
Le damos la bienvenida 🙏
Acabo de empezar a aprender sql y esto fue bueno para mí también.
gracias
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.