gpt4 book ai didi

powerbi - 行号分区依据到 POWER BI DAX 查询

转载 作者:行者123 更新时间:2023-12-05 06:13:58 25 4
gpt4 key购买 nike

谁能帮我把sql字符串转换成Dax?

row_number() p over(按日期分区,客户,按天输入订单) enter image description here

行号是我想要的输出。

最佳答案

假设您的数据如下表所示:

Sample
+------------+----------+---------+--------+
| Date | Customer | Product | Gender |
+------------+----------+---------+--------+
| 01/01/2018 | 1234 | P2 | F |
| 01/01/2018 | 1234 | P2 | M |
| 03/01/2018 | 1235 | P1 | F |
| 03/01/2018 | 1235 | P2 | F |
+------------+----------+---------+--------+

我使用 RANKX 和 FILTER 函数创建了一个名为 Rank 的计算列。

计算的第一部分是在 FILTER 函数范围之外创建变量。第二部分使用采用表达式值(在本例中为性别)的 RANKX 来对值进行排序。

Rank = 
VAR _currentdate = 'Sample'[Date]
VAR _customer = 'Sample'[Customer]
var _product = 'Sample'[Product]

return
RANKX(FILTER('Sample',
[Date]=_currentdate &&
[Customer] = _customer &&
[Product] = _product),[Gender],,ASC)

输出是

enter image description here

我将输出与等效的 SQL 进行了对比。

select 
*,
row_number() over(partition by Date,Customer,Product order by Gender)
from (
select '2018-01-01' as Date,1234 as CUSTOMER,'P2' AS PRODUCT, 'M' Gender union
select '2018-01-01' as Date,1234,'P2','F' UNION
select '2018-01-03' as Date,1235,'P1','F' UNION
select '2018-01-03' as Date,1235,'P2','F'
)t1

enter image description here

关于powerbi - 行号分区依据到 POWER BI DAX 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63102302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com