代码之家  ›  专栏  ›  技术社区  ›  Laki

年功率变化百分比

  •  0
  • Laki  · 技术社区  · 7 年前

    这是我在Power BI中的数据源: enter image description here

    然后我用这个公式计算了平均租金(对于“工作室”类型):

    AVGRentStudio = CALCULATE(AVERAGE('Rental Trend'[Rent]),'Rental Trend'[Type] = "Studio")
    

    我得到了一个平均值的表格: enter image description here

    现在我想计算一个年度百分比变化(到上一年)。

    这是我试过的,但结果不准确。

    RentChange =
    CALCULATE (
        IF (
            HASONEVALUE ( 'Rental Trend'[Year] ),
            DIVIDE (
                SUM ( 'Rental Trend'[Rent] ),
                CALCULATE (
                    SUM ( 'Rental Trend'[Rent] ),
                    'Rental Trend'[Year]
                        = FORMAT ( VALUES ( 'Rental Trend'[Year] ) - 1, BLANK () )
                )
            )
        )
            - 1,
        'Rental Trend'[Type] = "Studio"
    

    有谁能帮忙计算一下每年的百分比变化吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   RADO    7 年前

    一种方法是:

    措施1:

    Average Rent Studio =
    CALCULATE ( AVERAGE ( 'Rental Trend'[Rent] ), 'Rental Trend'[Type] = "Studio" )
    

    Average Rent Studio Previous Year =
    VAR Current_Year = MAX ( 'Rental Trend'[Year] )
    RETURN
        CALCULATE ( [Average Rent Studio], 'Rental Trend'[Year] = Current_Year - 1 )
    

    措施3:

    Average Rent Studio Y/Y Change = 
    DIVIDE([Average Rent Studio], [Average Rent Studio Previous Year])
    

    工作原理: 措施1和3很简单。 在度量2中,首先需要捕获当前年份(在给定的筛选器上下文中是最大年份)并将其存储在变量中。然后使用保存年份之前的1年重新计算工作室租金。

        2
  •  0
  •   Laki    7 年前

    @我根据你的回答有了个主意。

    措施1(前一年):

    AVG Rent Studio PY = CALCULATE(IF(HASONEVALUE('Rental Trend'[Year]), CALCULATE(AVERAGE('Rental Trend'[Rent]), 'Rental Trend'[Year] = FORMAT(VALUES('Rental Trend'[Year]) - 1, BLANK()), 'Rental Trend'[Type] = "Studio")))
    

    措施2(选定年份):

    VG Rent Studio CY = IF(HASONEVALUE('Rental Trend'[Year]), CALCULATE(AVERAGE('Rental Trend'[Rent]), 'Rental Trend'[Type] = "Studio"))
    

    措施3(逐年变化):

    Y/Y Rent Change = 1 - DIVIDE([AVG Rent Studio PY],[AVG Rent Studio CY])
    

    我是否可以使此解决方案动态化,以便根据“类型”选择显示逐年变化—Studio、1BDR、2BDR?

    谢谢