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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dhrupal_shah
Helper I
Helper I

result in value get proper t but while it put in row it not give result as per value

Dear all,

refer below screen shots and query,

i want result as 3rd screen if i put it in row or in value. 

thanks,

Dhrupal Shah

SELECT *
  ,W1=CASE WHEN Item_Width BETWEEN 0 AND 100 THEN 'W_0100' ELSE '' END
  ,W2=CASE WHEN Item_Width BETWEEN 100.01 AND 300 THEN 'W_100300' ELSE '' END
  ,W3=CASE WHEN Item_Width BETWEEN 300.01 AND 600 THEN 'W_300600' ELSE '' END
  ,W4=CASE WHEN Item_Width > 600.01 THEN 'W_abv600' ELSE '' END
  ,L1=CASE WHEN Item_Length BETWEEN 0 AND 300 THEN 'W_0300' ELSE '' END
  ,L2=CASE WHEN Item_Length BETWEEN 300.01 AND 600 THEN 'W_300600' ELSE '' END
  ,L3=CASE WHEN Item_Length BETWEEN 600.01 AND 900 THEN 'W_600900' ELSE '' END
  ,L4=CASE WHEN Item_Length >900.01 THEN 'W_abv900' ELSE '' END
 
  ,W1_0_100=CASE WHEN Item_Width BETWEEN 0 AND 100 THEN QtyRecv ELSE 0 END
  ,W2_100_300=CASE WHEN Item_Width BETWEEN 100.01 AND 300 THEN QtyRecv ELSE 0 END
  ,W3_300_600=CASE WHEN Item_Width BETWEEN 300.01 AND 600 THEN QtyRecv ELSE 0 END
  ,W4_abv_600=CASE WHEN Item_Width > 600.01 THEN QtyRecv ELSE 0 END
  ,L1_0_300=CASE WHEN Item_Length BETWEEN 0 AND 300 THEN QtyRecv ELSE 0 END
  ,L2_300_600=CASE WHEN Item_Length BETWEEN 300.01 AND 600 THEN QtyRecv ELSE 0 END
  ,L3_600_900=CASE WHEN Item_Length BETWEEN 600.01 AND 900 THEN QtyRecv ELSE 0 END
  ,L4_abv_900=CASE WHEN Item_Length >900.01 THEN QtyRecv ELSE 0 END

 

dhrupal_shah_0-1731311744121.png

 

dhrupal_shah_1-1731311763603.png

dhrupal_shah_3-1731311804185.png

 

 

4 REPLIES 4
saud968
Super User
Super User

If you want to sum quantities based on these categories, you might need to use aggregation functions like SUM() in your query.

Here’s a revised version of your query with some adjustments:

SQL

SELECT
CASE
WHEN Item_Width BETWEEN 0 AND 100 THEN 'W_0100'
WHEN Item_Width BETWEEN 100.01 AND 300 THEN 'W_100300'
WHEN Item_Width BETWEEN 300.01 AND 600 THEN 'W_300600'
WHEN Item_Width > 600.01 THEN 'W_abv600'
ELSE ''
END AS Width_Category,
CASE
WHEN Item_Length BETWEEN 0 AND 300 THEN 'L_0300'
WHEN Item_Length BETWEEN 300.01 AND 600 THEN 'L_300600'
WHEN Item_Length BETWEEN 600.01 AND 900 THEN 'L_600900'
WHEN Item_Length > 900.01 THEN 'L_abv900'
ELSE ''
END AS Length_Category,
SUM(CASE WHEN Item_Width BETWEEN 0 AND 100 THEN QtyRecv ELSE 0 END) AS W1_0_100,
SUM(CASE WHEN Item_Width BETWEEN 100.01 AND 300 THEN QtyRecv ELSE 0 END) AS W2_100_300,
SUM(CASE WHEN Item_Width BETWEEN 300.01 AND 600 THEN QtyRecv ELSE 0 END) AS W3_300_600,
SUM(CASE WHEN Item_Width > 600.01 THEN QtyRecv ELSE 0 END) AS W4_abv_600,
SUM(CASE WHEN Item_Length BETWEEN 0 AND 300 THEN QtyRecv ELSE 0 END) AS L1_0_300,
SUM(CASE WHEN Item_Length BETWEEN 300.01 AND 600 THEN QtyRecv ELSE 0 END) AS L2_300_600,
SUM(CASE WHEN Item_Length BETWEEN 600.01 AND 900 THEN QtyRecv ELSE 0 END) AS L3_600_900,
SUM(CASE WHEN Item_Length > 900.01 THEN QtyRecv ELSE 0 END) AS L4_abv_900
FROM YourTable
GROUP BY
CASE
WHEN Item_Width BETWEEN 0 AND 100 THEN 'W_0100'
WHEN Item_Width BETWEEN 100.01 AND 300 THEN 'W_100300'
WHEN Item_Width BETWEEN 300.01 AND 600 THEN 'W_300600'
WHEN Item_Width > 600.01 THEN 'W_abv600'
ELSE ''
END,
CASE
WHEN Item_Length BETWEEN 0 AND 300 THEN 'L_0300'
WHEN Item_Length BETWEEN 300.01 AND 600 THEN 'L_300600'
WHEN Item_Length BETWEEN 600.01 AND 900 THEN 'L_600900'
WHEN Item_Length > 900.01 THEN 'L_abv900'
ELSE ''
END;

This query categorizes the items based on width and length and sums the quantities received for each category. Adjust the table name (YourTable) to match your actual table name.


Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Dear Saud,

problem is while i put column (sql column0 in matrix in value the result get as i expected (W_0100 and in value of that column). but while put it in row it show me 0.1, 0.2 .... (mean value of that field) ,while i want that W_0100 AND qty as my measure not want to show multiple row.

dhrupal_shah_0-1731416111777.png

 

you might need to adjust how you’re structuring your query and how you’re using the matrix. Here are a few steps to help you:

Ensure Proper Grouping: Make sure your query groups the data correctly so that each category (e.g., W_0100) appears only once with the corresponding quantity.
Use Aggregation: When placing the column in the rows section, ensure that you’re using an aggregation function like SUM() to combine the quantities correctly.
Pivot the Data: If you’re using a tool like Power BI or Excel, you might need to pivot the data to get the desired format.
Here’s an example of how you might adjust your query:

SQL

SELECT
CASE
WHEN Item_Width BETWEEN 0 AND 100 THEN 'W_0100'
WHEN Item_Width BETWEEN 100.01 AND 300 THEN 'W_100300'
WHEN Item_Width BETWEEN 300.01 AND 600 THEN 'W_300600'
WHEN Item_Width > 600.01 THEN 'W_abv600'
ELSE ''
END AS Width_Category,
CASE
WHEN Item_Length BETWEEN 0 AND 300 THEN 'L_0300'
WHEN Item_Length BETWEEN 300.01 AND 600 THEN 'L_300600'
WHEN Item_Length BETWEEN 600.01 AND 900 THEN 'L_600900'
WHEN Item_Length > 900.01 THEN 'L_abv900'
ELSE ''
END AS Length_Category,
SUM(QtyRecv) AS Total_QtyRecv
FROM YourTable
GROUP BY
CASE
WHEN Item_Width BETWEEN 0 AND 100 THEN 'W_0100'
WHEN Item_Width BETWEEN 100.01 AND 300 THEN 'W_100300'
WHEN Item_Width BETWEEN 300.01 AND 600 THEN 'W_300600'
WHEN Item_Width > 600.01 THEN 'W_abv600'
ELSE ''
END,
CASE
WHEN Item_Length BETWEEN 0 AND 300 THEN 'L_0300'
WHEN Item_Length BETWEEN 300.01 AND 600 THEN 'L_300600'
WHEN Item_Length BETWEEN 600.01 AND 900 THEN 'L_600900'
WHEN Item_Length > 900.01 THEN 'L_abv900'
ELSE ''
END;

This query groups the data by width and length categories and sums the quantities received. When you use this result in your matrix, place Width_Category and Length_Category in the rows section and Total_QtyRecv in the values section.


Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

@dhrupal_shah was the above helpful

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.