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

How to convert a sql statement to dax

I am very new to Power BI and I am having a hard time converting a sql statement to dax.  I work in law enforcement and need to count the number of cases we have had during a certain date range in a 10 year period.  For example January 1 - June 15 for the years 2010 - 2019.  Following is my current sql statement:

WHERE (((Year([DATEOFDEAT]))>=2010) AND ((Month([DATEOFDEAT])) Between 1 And 5) AND ((Day([DATEOFDEAT]))<Date())) OR (((Year([DATEOFDEAT]))>=2010) AND ((Month([DATEOFDEAT]))=6) AND ((Day([DATEOFDEAT])) Between 1 And 15))

 

As a workaround, I created one dax statement for each year.  So, ten total dax statements for one report tile which feels like overkill.  Here is an example of the dax for year 2010:

1  Count of Murders 2010 =
2  CALCULATE(
3           COUNT(tblMurders[CN]),
4           DATESBETWEEN(
5                    tblMurders[DATEOFDEAT].[Date],
6                    DATE(2010,1,1),
7                    DATE(2010,6,15)
8           )
9  )
 
Any help would be very much appreciated.
 
Thanks!!!

 

1 ACCEPTED SOLUTION

@Anonymous 

 

If you want to use my idea of a MonthDay, you can create this calculated column in your datetable: (replace 'Table 2'[Date] references to your table name and date column):

MonthDay = VALUE(CONCATENATE(FORMAT(MONTH('Table 2'[Date]), "#"), FORMAT(DAY('Table 2'[Date]), "0#")))

Outcome:

image.png

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




View solution in original post

16 REPLIES 16

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.