简体   繁体   English

是否可以在Power BI中创建引用两个不共享关系的表的度量?

[英]Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. 我正在尝试在Power BI中创建一个矩阵表,以显示许多物业的月租金预测。 I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things. 我以为我可以简单地创建一个度量,将一张桌子的租金加起来,然后根据开始和结束日期的条件按月显示它,但是已经有一段时间了,因为我创建了任何度量,但是我忘记了需要建立联系列之间,等等。

Data Model 资料模型 资料模型

A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple. 一个站点可以具有多个关联的租赁,并且一个租赁可以具有与之关联的停车场和楼层,其中可以有多个。

In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur. 除了链接的图像中的表格之外,一旦我整理出我认为很容易的步骤,我将添加另一个表格,其中包括估计的租金增长百分比和增长周期。

I started out by trying to create a measure along the lines of the following: 我首先尝试按照以下方法创建度量:

Matrix Test =
IF (
    HASONEVALUE ( Period[Month] ),
    IF (
        Period[Month] >= Leases[Custom Start Date],
        SUM ( Floor_Rent[Annual Rent] ) / 12,
        0
    ),
    0
)

This would need to be expanded upon because the end date of a lease would also need to be taken into consideration. 这将需要扩展,因为还需要考虑租赁的结束日期。

As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column. 除了忘记关系要求之外,我还忘记了如何处理缩小到列中的单个值的问题。

The result is supposed to be something that looks like this: 结果应该是这样的:

结果示例

The blanks indicate a lease that starts in the future or ends within the time-frame displayed. 空白表示租赁开始于将来或在显示的时间范围内终止。

When I try linking the Leases table and the Period table on Leases[ Start month for current term ] and Period[ Month ] all I can get to is a table that shows the rent amount in the month the lease starts. 当我尝试在Leases [ 当前期限的开始月份 ]Period [ ]上链接Leases表和Period表时,我只能得到一张表,该表显示了租约开始月份的租金金额。

Is what I'm trying to achieve possible? 我要实现的目标有可能吗? If so, how do I accomplish the desired result? 如果是这样,我如何实现预期的结果?

Link to .pbix file 链接到.pbix文件

Solution

The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post . 标题问题的直接答案可能是“否”,但是在试图弄清楚如何使用Pratik Bhavsar的LOOKUPVALUE建议时,我产生了想法并执行了一个笨拙的Google搜索- 为列中的每个值创建表 bi-并找到这个帖子 By meddling with some of the DAX in said post I was able to come up with the following: 通过干预上述帖子中的一些DAX,我可以提出以下建议:

Test Table =
GENERATE(
    SELECTCOLUMNS(
        VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
    ),
    SELECTCOLUMNS(
        VALUES(Period[Month]),"Month",[Month]
    )
)

The result is a table with each Lease ID mapped against each Month. 结果是一个表格,其中每个租赁ID对应每个月。 I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do. 我不能声称完全了解这些功能的工作原理,也不是我认为所需的结果,但是它可以使我完全实现我打算要做的事情。

I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. 我接受了Pratik Bhavsar的回答,因为它有效地完成了与我实施的工作相同的工作。 Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare. Pratik的解决方案可能会比我最终找到的解决方案更好,但是我需要仔细研究两者的比较。

The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship. 以下DAX将为您提供一个表格,其中所有建筑物都映射到周期表中的所有行,从而消除了对关系的要求。

SiteToPeriod = 
CROSSJOIN(
    SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
    Period
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM