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
Anonymous
Not applicable

¿Cómo crear una medida DAX para esta consulta SQL?

Tengo un cálculo que es muy simple en SQL, pero no estoy teniendo éxito en obtener una medida DAX para hacer lo mismo.

declare @FromDate date = '2020-08-01';
declare @ToDate date = '2020-08-31';

with lia as
(	-- Get list of accounts that meet the criteria
	select	distinct AccountNo
	from	factLoan_Day fld
	where	dimDate between @FromDate and @ToDate
	and	Flag1 = 'Y'
)
-- For that list of accounts, divide the cash collected by the amount due
select	SUM(case when dtt.IsCashCollected = 'Y' then ft.transactionamount end)
		,SUM(case when dtt.TransactionType= 'DUE' then ft.transactionamount end)
		,SUM(case when dtt.IsCashCollected = 'Y' then ft.transactionamount end) / SUM(case when dtt.TransactionType = 'DUE' then ft.transactionamount end)
from	lia
join	factTransaction ft on ft.AccountNo = lia.AccountNo 
join	dimTransactionType dtt on dtt.dimTransactionType = ft.dimTransactionType
where	ft.dimDate between @FromDate and @ToDate;

¿Alguna idea?

2 REPLIES 2
VijayP
Super User
Super User

@EylesIT

Puede utilizar la función SWITCH con Calcular y Filtrar!

Si usted tiene los datos de muestra, entonces es mucho más fácil de explicar!




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


MFelix
Super User
Super User

Hola @EylesIT ,

¿Cómo tiene la configuración del modelo en Power BI también tiene todas las tablas a las que hace referencia en la consulta SQL? ¿Y tienes alguna relación entre las mesas?

En función de eso, la sintaxis DAX puede ser diferente y, en algunos casos, puede que ni siquiera sea necesaria para realizar cálculos complejos porque las medidas se basan en el contexto.

Si puede compartir algunos datos de muestra y el resultado esperado woud ser excelente.

Consulte esta publicación sobre cómo obtener respuestas a su pregunta rápidamente (cortesía de @Greg_Deckler) y Cómo proporcionar datos de ejemplo en el foro de Power BI (cortesía de @ImkeF).


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.