SQL Header Group by Query

SQL Header Group by Query

apallaro1
Not applicable
30 Views
2 Replies
Message 1 of 3

SQL Header Group by Query

apallaro1
Not applicable

[ FlexSim 24.1.0 ]

Hi,

I am making a query to get the best item type product based on certain conditions that must match. The problem is that I am not able to get the row headers with the item type that I am grouping by.

Is there a way to do this?

SQL Group By Example Headers.fsm

Here is the model.

In this example I want the final answer to be "30"


1718059956433.png

0 Likes
Accepted solutions (1)
31 Views
2 Replies
Replies (2)
Message 2 of 3

moehlmann_fe
Explorer
Explorer
Accepted solution

The result of the query is an internal data structure and doesn't have row headers, as far as I know. You will have to add the ModType column to the SELECT clause and treat it as its own column.

0 Likes
Message 3 of 3

apallaro1
Not applicable

You are right, that worked. Thanks


Table TableLineModules = Table.query("SELECT [ModType], SUM(CASE WHEN ([Zone] = 3 OR [Zone] = 4) then 1 else 0 END) as [Zone3&4], \

SUM(CASE WHEN ([Zone] = 5 OR [Zone] = 7) then 1 else 0 END) as [Zone5&7], \

COUNT(*) as [Total] \

FROM [Data] \

GROUP BY [ModType] \

ORDER BY [ModType] ASC ");

TableLineModules.cloneTo(Table("TableQuery1"));

0 Likes