是否可以使用切片器作为DAX Summarize函数的参数?

时间:2018-02-27 18:24:27

标签: powerbi dax

我有一个FactLosses表和一个DimAccumulation表。我已将它们带入PowerBi并且我已经放置了一个切片器来选择我感兴趣的累积区域。

一旦用户选择了区域,我想逐年对损失进行分组,并将损失汇总到年度分组中。但仅适用于适用于用户选择的区域的数据。

我正在使用以下DAX代码来完成这样的组...

表= SUMMARIZECOLUMNS(FactForwardLookingAccumulation [年],“按年损失”,SUM(FactForwardLookingAccumulation [净亏损我们的股票分享]))

问题是新表总是产生相同的结果。即当我改变应该包括哪些累积危险时,它对总和没有影响。 (它是对整个表的总结)

我想使用切片器过滤事实表,然后在过滤后的列表上运行DAX查询。这可能吗?

1 个答案:

答案 0 :(得分:0)

如果您希望这些表对报表上的过滤器或切片器做出响应,那么您不能将这些表写为显示在“数据”选项卡下的计算表,因为这些表是在任何过滤发生之前计算的。

为了获得你想要的东西,你必须在一个尺度内做所有事情,因为那些是对切片机的反应。如果您在分组和求和完成后正在寻找最大损失年份,您可以按以下方式编写一个度量:

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXDrawer?>
<?import com.jfoenix.controls.JFXListView?>
<?import com.jfoenix.controls.JFXPopup?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.web.WebView?>

<AnchorPane id="AnchorPane" fx:id="pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="1395.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gis_map.ZoningController">
   <children>
      <MenuBar layoutY="2.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="1395.0">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Exit" />
                  <MenuItem mnemonicParsing="false" text="Save" />
                  <MenuItem mnemonicParsing="false" text="Create new project" />
                  <MenuItem mnemonicParsing="false" text="Open project" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Edit">
            <items>
                  <MenuItem mnemonicParsing="false" text="Undo" />
              <MenuItem mnemonicParsing="false" text="Redo" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Help">
            <items>
              <MenuItem mnemonicParsing="false" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
      <TreeView fx:id="treeview" layoutY="27.0" prefHeight="438.0" prefWidth="184.0" />
      <TabPane layoutX="947.0" layoutY="27.0" prefHeight="623.0" prefWidth="444.0" tabClosingPolicy="UNAVAILABLE">
        <tabs>
            <Tab text="Tools">
               <content>
                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="559.0" prefWidth="444.0">
                     <children>
                        <Button fx:id="cluster" layoutX="55.0" layoutY="50.0" mnemonicParsing="false" onAction="#clusterMakers" prefHeight="25.0" prefWidth="161.0" text="Cluster" />
                        <Button fx:id="btnsolver" layoutX="55.0" layoutY="116.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="129.0" text="Run VPR_Solver" />
                     </children>
                  </AnchorPane>
               </content>
            </Tab>
            <Tab text="Traffic Watch">
              <content>
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                     <children>
                        <TitledPane animated="false" layoutY="-1.0" prefHeight="593.0" prefWidth="444.0" text="Traffic News">
                          <content>
                            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="476.0" prefWidth="449.0">
                                 <children>
                                     <ImageView fx:id="imageview" fitHeight="273.0" fitWidth="291.0" layoutX="72.0" layoutY="267.0" pickOnBounds="true" preserveRatio="true" />
                                    <Button fx:id="portLouis" layoutX="170.0" layoutY="344.0" mnemonicParsing="false" onAction="#showdrawer" />
                                    <Button fx:id="test" layoutX="178.0" layoutY="307.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <Button fx:id="test1" layoutX="251.0" layoutY="369.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <Button fx:id="test2" layoutX="186.0" layoutY="391.0" mnemonicParsing="false" onAction="#mokaDrawer" />
                                    <Button fx:id="test3" layoutX="157.0" layoutY="416.0" mnemonicParsing="false" onAction="#plaineWilhemDrawer" />
                                    <Button fx:id="test4" layoutX="225.0" layoutY="448.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <Button fx:id="test5" layoutX="243.0" layoutY="307.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <Button fx:id="test6" layoutX="114.0" layoutY="416.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <Button fx:id="test7" layoutX="157.0" layoutY="493.0" mnemonicParsing="false" onAction="#ifthereisnocamera" />
                                    <JFXListView fx:id="listview" layoutY="-2.0" prefHeight="263.0" prefWidth="392.0" />
                                    <JFXPopup fx:id="popup" layoutX="14.0" layoutY="14.0" />
                                 </children></AnchorPane>
                          </content>
                        </TitledPane>
                     </children>
                  </AnchorPane>
              </content>
            </Tab>
          <Tab text="Working Team">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="559.0" prefWidth="444.0">
                     <children>
                        <Label layoutX="14.0" layoutY="32.0" text="Number of workers" />
                        <Label layoutX="290.0" layoutY="93.0" text="Selection" />
                        <TextField layoutX="156.0" layoutY="28.0" />
                        <ListView layoutX="32.0" layoutY="132.0" prefHeight="200.0" prefWidth="147.0" />
                        <ListView layoutX="237.0" layoutY="132.0" prefHeight="200.0" prefWidth="154.0" />
                        <Button layoutX="189.0" layoutY="194.0" mnemonicParsing="false" text="&gt;&gt;" />
                        <Button layoutX="189.0" layoutY="260.0" mnemonicParsing="false" text="&lt;&lt;" />
                        <Label layoutX="23.0" layoutY="398.0" text="Driver" />
                        <ChoiceBox layoutX="138.0" layoutY="394.0" prefWidth="150.0" />
                        <Label layoutX="51.0" layoutY="93.0" text="Waste collectors" />
                     </children>
                  </AnchorPane>
            </content>
          </Tab>
          <Tab text="Vehicles">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="543.0" prefWidth="444.0">
                     <children>
                        <TitledPane animated="false" prefHeight="490.0" prefWidth="444.0" text="choose vehicle">
                          <content>
                            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="510.0" prefWidth="442.0">
                                 <children>
                                    <Label layoutX="40.0" layoutY="173.0" text="Vehicle 1" />
                                    <Label layoutX="40.0" layoutY="400.0" text="Vehicle 2" />
                                    <Label layoutX="327.0" layoutY="173.0" text="Vehicle 3" />
                                    <Label layoutX="351.0" layoutY="400.0" text="Vehicle 4" />
                                 </children>
                              </AnchorPane>
                          </content>
                        </TitledPane>
                     </children>
                  </AnchorPane>
            </content>
          </Tab>
            <Tab text="Accidents News">
               <content>
                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="567.0" prefWidth="444.0">
                     <children>
                        <WebView fx:id="accidentView" layoutX="1.0" layoutY="1.0" prefHeight="566.0" prefWidth="444.0" />
                     </children>
                  </AnchorPane>
               </content>
            </Tab>
        </tabs>
      </TabPane>
      <TitledPane animated="false" layoutX="-1.0" layoutY="465.0" prefHeight="186.0" prefWidth="184.0" text="Selection Options">
        <content>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
               <children>
                  <Button fx:id="radius" layoutX="14.0" layoutY="14.0" mnemonicParsing="false" onAction="#openRadius" prefHeight="25.0" prefWidth="140.0" text="Within Radius" />
                  <Button layoutX="14.0" layoutY="55.0" mnemonicParsing="false" onAction="#activateMeasurement" prefHeight="25.0" prefWidth="139.0" text="Near roads" />
               </children>
            </AnchorPane>
        </content>
      </TitledPane>
      <JFXDrawer fx:id="drawer" direction="TOP" disable="true" layoutX="183.0" layoutY="27.0" prefHeight="623.0" prefWidth="763.0" />
      <WebView fx:id="webview" layoutX="184.0" layoutY="27.0" prefHeight="623.0" prefWidth="763.0" />
   </children>
</AnchorPane>

以这种方式编写将允许计算表响应切片器和过滤器。