如何使用重复值进行累加

时间:2019-07-11 10:13:04

标签: powerbi dax

[http://uupload.ir/view/v2t_capture.png]我们有2个带有2列的表:

  1. 表位置->列->城市,省
  2. 表格销售列->实际销售
unpad()

我想计算每个城市和每个省的总销售额的80% 这意味着如果我们在全省的总销售量为2800,我们只想显示削减80%的销售量的省份:

我使用这种方法,但是有一个问题,重复值不计入累计和。

如果我有两次相同的销售(例如900),则不会累计,并且会忽略它。

def encrypt_array(arr,key_encrypt,iv_encrypt):
    print("key_encrypt:",key_encrypt)
    arr_bytes=array([3,3])
    print("arr_bytes shape:",arr_bytes.shape)
    print("arr_bytes shape:",arr_bytes.dtype)
    arr_bytes=arr[:3,:3].tobytes()
    print("length:",len(arr_bytes))
    print("arr_bytes:",arr_bytes)
    cipher1 = AES.new(key_encrypt, AES.MODE_CBC,iv_encrypt)
    cipher_text=cipher1.encrypt(pad(arr_bytes,AES.block_size))
    #print(cipher_text)
    return(cipher_text)

def decrypt_array(for_decrypt,key_decrypt,iv_decrypt):
    print("key_decrypt:",key_decrypt)
    print("IV_decrypt:",iv_decrypt)
    decipher=AES.new(key_decrypt,AES.MODE_CFB,iv_decrypt)
    decipher_text=unpad(decipher.decrypt(for_decrypt),AES.block_size)
    return(decipher_text)

def main():
    ar = array([[1,2,3],
                [4,5,6],
                [7,8,9]])
    print("type:",ar.dtype)
    key = get_random_bytes(16)
    print("key;",key)
    iv = get_random_bytes(16)
    print("IV:",iv)
    cipher_t = encrypt_array(ar,key,iv)
    decipher_t = decrypt_array(cipher_t,key,iv)

预期结果:

table location : table sales 
province  city       id     sales
tehran    eslamshar  1      100
tehran    rey        2      500
hamedan   tefresh    3      500
esfahan   esahan     4      400
gilan     rasht      5      400
gilan     rar        6      900

输出:

Cumulative Total =
IF (
    NOT ( ISBLANK ( [sales] ) ),
    CALCULATE (
        [sales],
        FILTER (
            ALL ( DimLocation[Province] ),
            CALCULATE ( [sales], VALUES ( DimLocation[Province] ) ) <= [sales]
        )
    )
)

1 个答案:

答案 0 :(得分:0)

对于总计,您可以创建以下度量:

RT Province Sales := 
VAR _current = SELECTEDVALUE ( DimLocation[Province] )
RETURN
    CALCULATE (
        [Sales], 
        DimLocation[Province] <= _current , 
        ALL ( DimLocation[Province] )
    )