我正在编写一个从SQL中获取信息的PowerBI报告,但是我找不到使用PowerBI解决问题的方法,也找不到如何编写所需代码的方法。我的第一个表,认证,包括一个认证和所需培训的列表,为了获得有效的认证必须获得这些培训。
我的第二个表UserCertifications包含一个用户My、认证和与认证相关的培训的列表。
如何编写SQL代码或PowerBI度量来判断用户是否接受了认证所需的所有培训?即,如果UserID 1具有A认证,我如何验证他们是否具有关联的培训it 1、10和150?
UserCertifications:UserCertificationsTable
发布于 2021-10-01 00:53:05
这是一个DAX模式,用于测试是否至少包含一些值。
| Certifications |
|----------------|------------|
| Certification | TrainingID |
|----------------|------------|
| A | 1 |
| A | 10 |
| A | 150 |
| B | 7 |
| B | 9 |
| UserCertifications |
|--------------------|---------------|----------|
| UserID | Certification | Training |
|--------------------|---------------|----------|
| 1 | A | 1 |
| 1 | A | 10 |
| 1 | A | 300 |
| 2 | A | 150 |
| 2 | B | 9 |
| 2 | B | 90 |
| 3 | A | 7 |
| 4 | A | 1 |
| 4 | A | 10 |
| 4 | A | 150 |
| 4 | A | 1000 |
在上面的场景中,DAX需要检查Certifications[Certification]
的强制训练(Certifications[TrainingID])
是否由UserCertifications[UserID ]
&&UserCertifications[Certifications]
分区完成。
在上面的场景中,DAX应该只为UserCertifications[UserID ]=4
返回true,因为它是唯一至少完成了所有强制性培训的用户。
实现这一点的方法是通过以下措施
areAllMandatoryTrainingCompleted =
VAR _alreadyCompleted =
CONCATENATEX (
UserCertifications,
UserCertifications[Training],
"-",
UserCertifications[Training]
) // what is completed in the fact Table; the fourth argument is very important as it decides the sort order
VAR _0 =
MAX ( UserCertifications[Certification] )
VAR _supposedToComplete =
CONCATENATEX (
FILTER ( Certifications, Certifications[Certification] = _0 ),
Certifications[TrainingID],
"-",
Certifications[TrainingID]
) // what is comeleted in the training Table; the fourth argument is very important as it decides the sort order
VAR _isMandatoryTrainingCompleted =
CONTAINSSTRING ( _alreadyCompleted, _supposedToComplete ) // CONTAINSSTRING (<Within Text>,<Search Text>); return true false
RETURN
_isMandatoryTrainingCompleted
https://stackoverflow.com/questions/69398003
复制相似问题