Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
neil37
Advocate I
Advocate I

Python to DAX Conversion

Hello, 

 

We are trying to convert the following python code into DAX. The goal is to

distinct count of case number (caseno) grouped by (year), where occ date/time (occuron) is like YYYY
 

Any help or assitance is greatly appreciated. Anything bolded is the column name in our dataset. Anything underlined denotes the table. The tables and columns would be indicated in DAX like: (e.g., 'table' and [column] would come from this: 'wa offense'[caseno]

 

SELECT date_format(occuron, '%Y') AS occuronyear, count(DISTINCT caseno) AS dis_caseno FROM wa offense GROUP BY date_format(occuron, '%Y')
____________________
Specfic ibroff category:
 
SELECT date_format(occuron, '%Y') AS occuronyear, count(DISTINCT caseno) AS dis_caseno, ibroff
FROM wa offense
GROUP BY date_format(occuron, '%Y'), ibroff
 
 
Alternatively, is there a way to utilize python instead of DAX? Thank you!
1 REPLY 1
rfigtree
Resolver III
Resolver III

hi i only know how to write dax within power pivot, but i think you would write something like this.

if it doesnt work the concept is correct, might just need to tweak the syntax to suit your environment.

 

 

evaluate

    summarize(
                addcolumns(table,"Year",format(table[date],"yyyy"),
                [Year],
                [caseno]
              )

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.