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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

SQL to DAX Convert

Hello,

 

 

I'm new to DAX, please help to convert below T-SQL code to its equivalnet DAX.

I 'm generating running total (cummulative) using TSQL the same  i need in DAX, please help

 

 

select src.Final_date, sum([Units Assigned]) over(order by src.Final_date) as Final_cnt 
from (

select  [Received Date] as Final_date,   count(CARGO_ID) as [Units Assigned] from dbo.table1 where 
[Status]='ASSIGNED' and [Type]='TENDERED' and Dashboard='Inventory'
group by [Received Date]

) src
order by  src.Final_date desc

 

 

Thanks in advance

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Modify the formula like this:

EVALUATE 
	VAR tab =
	SUMMARIZE(
		FILTER(
			'Inv_Fact_Inventory',
			'Inv_Fact_Inventory'[Dashboard] = "Current Inventory" &&
			'Inv_Fact_Inventory'[Inventory Order Type] = "TENDERED" &&
			'Inv_Fact_Inventory'[Inventory Status] = "ASSIGNED"
		),
		'Inv_Fact_Inventory'[Received Date],
		"Units Assigned",
		 CALCULATE(COUNT(Inv_Fact_Inventory[CURINV_CARGO_ID]))
	)
RETURN
SELECTCOLUMNS(
	tab,
	"Final_Cut",
	var d = 'Inv_Fact_Inventory'[Received Date]
	return
	SUMX(
		FILTER(
			tab,
			[Received Date] <= d
		),
		[Units Assigned]
	)
)

order by [Final_Cut] desc

You may get your expected result, below is my sample and result:

t1.pngr1.png

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Try to use this formula to create a calculate table, and use 'Sort descending' in the Data view:

A =
VAR tab =
    SUMMARIZE (
        FILTER (
            'dbo.table1',
            [Status] = "ASSIGNED"
                && [Type] = 'TENDERED'
                && [Dashboard] = 'Inventory'
        ),
        "Final_date", 'dbo.table1'[Received Date],
        "Units Assigned", COUNT ( 'dbo.table1'[CARGO_ID] )
    )
RETURN
    SELECTCOLUMNS (
        tab,
        "Final_cut", SUMX ( FILTER ( tab, [Final_date] <= MAX ( [Final_date] ) ), [Units Assigned] )
    )

desc.png

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks for your reply! . I'm having issue at this step:

 

EVALUATE 
	    SUMMARIZE (
        FILTER ( Inv_Fact_Inventory, 
						Inv_Fact_Inventory[Dashboard]="Current Inventory" && Inv_Fact_Inventory[Inventory Status]="ASSIGNED" && Inv_Fact_Inventory[Inventory Order Type]="TENDERED NOT SHIPPED" ),
,
        "Final_date", Inv_Fact_Inventory[Received Date],
        "Units Assigned", DISTINCTCOUNT(Inv_Fact_Inventory[CURINV_CARGO_ID])
    )

 

At Final_Date, below is the error

 

sarthaks_0-1594635594082.png

Next when i try to run the whole expression im getting the same value for all records.Am i missing something here..

 

Here is the updated code im using now:

EVALUATE 
	VAR tab =
    SUMMARIZE (
        FILTER (
             Inv_Fact_Inventory, 
						Inv_Fact_Inventory[Dashboard]="Current Inventory" && Inv_Fact_Inventory[Inventory Status]="ASSIGNED" && Inv_Fact_Inventory[Inventory Order Type]="TENDERED NOT SHIPPED" 
        ),
        Inv_Fact_Inventory[Received Date],
        "Units Assigned", DISTINCTCOUNT( Inv_Fact_Inventory[CURINV_CARGO_ID] )
    )
RETURN
    SELECTCOLUMNS (
        tab,
        "Final_cut", SUMX ( FILTER ( tab, Inv_Fact_Inventory[Received Date] <= MAX ( Inv_Fact_Inventory[Received Date] ) ), [Units Assigned] )
    )

 

Output:

 

sarthaks_1-1594635837039.png

 

Please advice

 

 

Hi @Anonymous ,

Modify the formula like this:

EVALUATE 
	VAR tab =
	SUMMARIZE(
		FILTER(
			'Inv_Fact_Inventory',
			'Inv_Fact_Inventory'[Dashboard] = "Current Inventory" &&
			'Inv_Fact_Inventory'[Inventory Order Type] = "TENDERED" &&
			'Inv_Fact_Inventory'[Inventory Status] = "ASSIGNED"
		),
		'Inv_Fact_Inventory'[Received Date],
		"Units Assigned",
		 CALCULATE(COUNT(Inv_Fact_Inventory[CURINV_CARGO_ID]))
	)
RETURN
SELECTCOLUMNS(
	tab,
	"Final_Cut",
	var d = 'Inv_Fact_Inventory'[Received Date]
	return
	SUMX(
		FILTER(
			tab,
			[Received Date] <= d
		),
		[Units Assigned]
	)
)

order by [Final_Cut] desc

You may get your expected result, below is my sample and result:

t1.pngr1.png

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Your solution worked. Thanks for help..

amitchandak
Super User
Super User

@Anonymous , Try like

sumx(values(Table[Received Date]), calculate(count(Table[CARGO_ID]),filter(Table, table[Status]="ASSIGNED" && table[Type]="TENDERED" && table[Dashboard]="Inventory")))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Its not working.

 

I'm not getting values based on the formula that you have provided.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.