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

CAMBIAR DAX A SQL

Hola necesito pasar de codigo dax a sql lo siguiente:

 

LastPhaseStatusFiltered =
VAR maxDate =
CALCULATE ( MAX ( 'Ventas'[DateTime] ), ALLSELECTED ( 'Ventas'[DateTime] ) )
RETURN
CALCULATE ( MIN ( 'Ventas'[PhaseStatus] ), 'Ventas'[DateTime] = maxDate )
 
Alguien me podria ayudar.
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I'm not an expert on SQL but to my knowledge you need to have a select as a filter or similar to get the data so you would need something similar to:

 

 

Select
   MIN (table1.PhaseStatus),
   table1.DateTime 
From
   'Ventas' as table1 
Where
   table1.dtmData = 
   (
      Select
         mAX ( table2.DateTime) as datemax 
      from
         'Ventas' table2 
   )
group by
   table1.DateTime

 

 

Be aware that the allselected is a way of getting filtered data in DAX so if you need to filter the information you need to had values to it.

 

This table will only give you a single value because it's picking up the maximum date of the table and returning the minimum value for that date if you want the minimum value for all the dates in your table you should use the following SQL:

 

Select
   MIN (table1.PhaseStatus),
   table1.DateTime 
From
   'Ventas' as table1 
group by
   table1.DateTime

 

This will return a table with all dates and for each one the minimum value.

 

@Greg_Deckler 👍 I'm not an expert in SQL probably there are some gurus outthere in the forum but I can make my way around it, thanks for the shout out.

 

 


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



View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Probablemente no sea el mejor foro para eso, no estoy seguro de quién es el experto residente de SQL @MFelix ?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Anonymous ,

 

I'm not an expert on SQL but to my knowledge you need to have a select as a filter or similar to get the data so you would need something similar to:

 

 

Select
   MIN (table1.PhaseStatus),
   table1.DateTime 
From
   'Ventas' as table1 
Where
   table1.dtmData = 
   (
      Select
         mAX ( table2.DateTime) as datemax 
      from
         'Ventas' table2 
   )
group by
   table1.DateTime

 

 

Be aware that the allselected is a way of getting filtered data in DAX so if you need to filter the information you need to had values to it.

 

This table will only give you a single value because it's picking up the maximum date of the table and returning the minimum value for that date if you want the minimum value for all the dates in your table you should use the following SQL:

 

Select
   MIN (table1.PhaseStatus),
   table1.DateTime 
From
   'Ventas' as table1 
group by
   table1.DateTime

 

This will return a table with all dates and for each one the minimum value.

 

@Greg_Deckler 👍 I'm not an expert in SQL probably there are some gurus outthere in the forum but I can make my way around it, thanks for the shout out.

 

 


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



amitchandak
Super User
Super User

@Anonymous , You need SQL for this ?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.